AddressCompletionPage.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <q-page class="address-completion-page bg-surface">
  3. <div class="address-completion-inner">
  4. <q-btn
  5. class="address-completion-back"
  6. color="primary"
  7. dense
  8. flat
  9. icon="mdi-arrow-left"
  10. round
  11. @click="router.back()"
  12. />
  13. <q-form
  14. ref="addressForm"
  15. class="address-completion-content"
  16. >
  17. <div class="text-text">
  18. <span class="font14 fontbold">{{ $t("common.terms.document") }}</span>
  19. </div>
  20. <q-input
  21. v-model="form.document"
  22. class="bg-surface q-mt-sm q-mb-md"
  23. hide-bottom-space
  24. input-class="text-text"
  25. lazy-rules
  26. no-error-icon
  27. outlined
  28. rounded
  29. :placeholder="$t('common.terms.document')"
  30. :rules="[inputRules.cpfOrCnpj]"
  31. />
  32. <div class="text-text">
  33. <span class="font14 fontbold">{{ $t("common.terms.phone") }}</span>
  34. </div>
  35. <q-input
  36. v-model="form.phone"
  37. class="bg-surface q-mt-sm q-mb-md"
  38. hide-bottom-space
  39. input-class="text-text"
  40. lazy-rules
  41. mask="(##) #####-####"
  42. no-error-icon
  43. outlined
  44. rounded
  45. :placeholder="$t('common.terms.phone')"
  46. :rules="[inputRules.required, inputRules.phone]"
  47. />
  48. <div class="text-text">
  49. <span class="font14 fontbold">{{ $t("common.terms.address") }}</span>
  50. </div>
  51. <q-input
  52. :model-value="flowStore.confirmedAddress"
  53. class="bg-surface q-mt-sm q-mb-md"
  54. input-class="text-text"
  55. outlined
  56. readonly
  57. rounded
  58. />
  59. <div class="row q-col-gutter-sm">
  60. <div class="col-4">
  61. <div class="text-text">
  62. <span class="font14 fontbold">{{
  63. $t("common.terms.address_number")
  64. }}</span>
  65. </div>
  66. <q-input
  67. v-model="form.number"
  68. class="bg-surface q-mt-sm q-mb-md"
  69. hide-bottom-space
  70. input-class="text-text"
  71. lazy-rules
  72. no-error-icon
  73. outlined
  74. placeholder="0000"
  75. rounded
  76. :rules="[inputRules.required]"
  77. />
  78. </div>
  79. <div class="col-8">
  80. <div class="text-text">
  81. <span class="font14 fontbold">{{
  82. $t("common.terms.district")
  83. }}</span>
  84. </div>
  85. <q-input
  86. :model-value="flowStore.confirmedDistrict"
  87. :rules="[inputRules.required]"
  88. class="bg-surface q-mt-sm q-mb-md"
  89. hide-bottom-space
  90. input-class="text-text"
  91. lazy-rules
  92. no-error-icon
  93. outlined
  94. readonly
  95. rounded
  96. />
  97. </div>
  98. </div>
  99. <div class="row q-col-gutter-sm">
  100. <div class="col-8">
  101. <div class="text-text">
  102. <span class="font14 fontbold">{{ $t("common.terms.city") }}</span>
  103. </div>
  104. <q-input
  105. :model-value="flowStore.confirmedCity"
  106. :rules="[inputRules.required]"
  107. class="bg-surface q-mt-sm q-mb-md"
  108. hide-bottom-space
  109. input-class="text-text"
  110. lazy-rules
  111. no-error-icon
  112. outlined
  113. readonly
  114. rounded
  115. />
  116. </div>
  117. <div class="col-4">
  118. <div class="text-text">
  119. <span class="font14 fontbold">
  120. {{ $t("common.terms.state") }}
  121. </span>
  122. </div>
  123. <q-input
  124. :model-value="flowStore.confirmedState"
  125. :rules="[inputRules.required]"
  126. class="bg-surface q-mt-sm q-mb-md"
  127. hide-bottom-space
  128. input-class="text-text"
  129. lazy-rules
  130. no-error-icon
  131. outlined
  132. readonly
  133. rounded
  134. />
  135. </div>
  136. </div>
  137. <q-checkbox
  138. v-model="form.no_complement"
  139. class="q-mb-md text-text"
  140. color="primary"
  141. keep-color
  142. :label="$t('auth.no_complement')"
  143. />
  144. <template v-if="!form.no_complement">
  145. <div class="text-text">
  146. <span class="font14 fontbold">{{ $t("auth.complement") }}</span>
  147. </div>
  148. <q-input
  149. v-model="form.complement"
  150. class="bg-surface q-mt-sm q-mb-md"
  151. input-class="text-text"
  152. outlined
  153. rounded
  154. :placeholder="$t('auth.complement_placeholder')"
  155. />
  156. </template>
  157. <div class="text-text">
  158. <span class="font14 fontbold">{{ $t("auth.address_nickname") }}</span>
  159. </div>
  160. <q-input
  161. v-model="form.nickname"
  162. class="bg-surface q-mt-sm q-mb-md"
  163. input-class="text-text"
  164. outlined
  165. rounded
  166. :placeholder="$t('auth.address_nickname_placeholder')"
  167. />
  168. <div class="text-text">
  169. <span class="font14 fontbold">
  170. {{ $t("auth.address_instructions") }}
  171. </span>
  172. </div>
  173. <q-input
  174. v-model="form.instructions"
  175. autogrow
  176. class="bg-surface q-mt-sm q-mb-md"
  177. input-class="text-text"
  178. outlined
  179. rounded
  180. rows="3"
  181. type="textarea"
  182. />
  183. <div class="row q-gutter-sm q-mt-xs q-mb-xl">
  184. <q-chip
  185. v-for="type in addressTypes"
  186. :key="type.value"
  187. :icon="type.icon"
  188. :icon-selected="type.icon"
  189. :outline="form.address_type !== type.value"
  190. :selected="form.address_type === type.value"
  191. clickable
  192. color="primary"
  193. text-color="surface"
  194. @click="form.address_type = type.value"
  195. >
  196. {{ type.label }}
  197. </q-chip>
  198. </div>
  199. </q-form>
  200. <div class="address-completion-footer">
  201. <q-btn
  202. class="full-width"
  203. color="primary-button"
  204. padding="14px 16px"
  205. rounded
  206. :label="$t('auth.confirm_address')"
  207. :loading="submitting"
  208. @click="handleConfirm"
  209. />
  210. </div>
  211. </div>
  212. </q-page>
  213. </template>
  214. <script setup>
  215. import { computed, onMounted, ref } from "vue";
  216. import { createUserAndClient } from "src/api/user";
  217. import { useAuth } from "src/composables/useAuth";
  218. import { useI18n } from "vue-i18n";
  219. import { useInputRules } from "src/composables/useInputRules";
  220. import { useQuasar } from "quasar";
  221. import { useRegistrationFlowStore } from "src/stores/registrationFlow";
  222. import { useRouter } from "vue-router";
  223. const { t } = useI18n();
  224. const router = useRouter();
  225. const $q = useQuasar();
  226. const { setAuthDataFromPayload } = useAuth();
  227. const { inputRules } = useInputRules();
  228. const flowStore = useRegistrationFlowStore();
  229. const addressForm = ref(null);
  230. const submitting = ref(false);
  231. const form = ref({
  232. document: flowStore.document || "",
  233. number: "",
  234. no_complement: false,
  235. complement: "",
  236. nickname: "",
  237. instructions: "",
  238. address_type: "home",
  239. phone: flowStore.phone || "",
  240. });
  241. const addressTypes = computed(() => [
  242. {
  243. value: "home",
  244. label: t("auth.address_type_home"),
  245. icon: "mdi-home-outline",
  246. },
  247. {
  248. value: "commercial",
  249. label: t("auth.address_type_commercial"),
  250. icon: "mdi-office-building-outline",
  251. },
  252. {
  253. value: "other",
  254. label: t("auth.address_type_other"),
  255. icon: "mdi-map-marker-outline",
  256. },
  257. ]);
  258. const handleConfirm = async () => {
  259. const isValid = await addressForm.value?.validate();
  260. if (!isValid) return;
  261. if (!form.value.no_complement && !form.value.complement?.trim()) {
  262. $q.notify({ type: "warning", message: t("auth.complement_required") });
  263. return;
  264. }
  265. submitting.value = true;
  266. try {
  267. const payload = {
  268. email: flowStore.email || undefined,
  269. phone: form.value.phone,
  270. document: form.value.document,
  271. name: flowStore.name || undefined,
  272. code: flowStore.code,
  273. zip_code: flowStore.confirmedZipCode || undefined,
  274. address: flowStore.confirmedAddress || undefined,
  275. number: form.value.number || undefined,
  276. district: flowStore.confirmedDistrict || undefined,
  277. city: flowStore.confirmedCity || undefined,
  278. state: flowStore.confirmedState || undefined,
  279. latitude: flowStore.confirmedLat,
  280. longitude: flowStore.confirmedLng,
  281. has_complement: !form.value.no_complement,
  282. complement: form.value.no_complement
  283. ? null
  284. : form.value.complement || null,
  285. nickname: form.value.nickname || null,
  286. instructions: form.value.instructions || null,
  287. address_type: form.value.address_type,
  288. };
  289. const response = await createUserAndClient(payload);
  290. if (response.status >= 200 && response.status < 300) {
  291. await setAuthDataFromPayload(response.data.payload);
  292. flowStore.clear();
  293. router.push({ name: "DashboardPage" });
  294. }
  295. } catch {
  296. $q.notify({ type: "negative", message: t("auth.register_error") });
  297. } finally {
  298. submitting.value = false;
  299. }
  300. };
  301. onMounted(() => {
  302. if (!flowStore.hasConfirmedLocation() || !flowStore.hasCredentials()) {
  303. router.replace({ name: "LoginPage" });
  304. return;
  305. }
  306. form.value.number = flowStore.confirmedNumber || "";
  307. });
  308. </script>
  309. <style lang="scss" scoped>
  310. .address-completion-page {
  311. min-height: 100dvh;
  312. display: flex;
  313. justify-content: center;
  314. }
  315. .address-completion-inner {
  316. width: 100%;
  317. max-width: 500px;
  318. min-height: 100dvh;
  319. display: flex;
  320. flex-direction: column;
  321. padding: 16px 20px;
  322. }
  323. .address-completion-back {
  324. align-self: flex-start;
  325. margin-bottom: 12px;
  326. margin-top: env(safe-area-inset-top);
  327. }
  328. .address-completion-content {
  329. flex: 1;
  330. }
  331. .address-type-row {
  332. display: flex;
  333. gap: 10px;
  334. flex-wrap: wrap;
  335. }
  336. .address-completion-footer {
  337. padding: 16px 0 calc(12px + env(safe-area-inset-bottom));
  338. }
  339. </style>