|
@@ -163,7 +163,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, onBeforeMount, useTemplateRef } from "vue";
|
|
|
|
|
|
|
+import { ref, watch, onBeforeMount, useTemplateRef } from "vue";
|
|
|
import { useQuasar } from "quasar";
|
|
import { useQuasar } from "quasar";
|
|
|
import { useI18n } from "vue-i18n";
|
|
import { useI18n } from "vue-i18n";
|
|
|
import { useRouter } from "vue-router";
|
|
import { useRouter } from "vue-router";
|
|
@@ -214,12 +214,41 @@ const form = ref({
|
|
|
|
|
|
|
|
const isLocked = (field) => lockedFields.value.includes(field);
|
|
const isLocked = (field) => lockedFields.value.includes(field);
|
|
|
|
|
|
|
|
|
|
+const unlockField = (field) => {
|
|
|
|
|
+ lockedFields.value = lockedFields.value.filter((locked) => locked !== field);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
const {
|
|
const {
|
|
|
loading,
|
|
loading,
|
|
|
validationErrors,
|
|
validationErrors,
|
|
|
execute: submitForm,
|
|
execute: submitForm,
|
|
|
} = useSubmitHandler({ formRef });
|
|
} = useSubmitHandler({ formRef });
|
|
|
|
|
|
|
|
|
|
+const prefillRules = {
|
|
|
|
|
+ name: [inputRules.required],
|
|
|
|
|
+ cpf: [inputRules.required, inputRules.cpf],
|
|
|
|
|
+ email: [inputRules.required, inputRules.email],
|
|
|
|
|
+ phone: [inputRules.required],
|
|
|
|
|
+ position_id: [inputRules.required],
|
|
|
|
|
+ sector_id: [inputRules.required],
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const unlockInvalidFields = () => {
|
|
|
|
|
+ Object.entries(prefillRules).forEach(([field, rules]) => {
|
|
|
|
|
+ if (!isLocked(field)) return;
|
|
|
|
|
+
|
|
|
|
|
+ if (rules.some((rule) => rule(form.value[field]) !== true)) {
|
|
|
|
|
+ unlockField(field);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+watch(
|
|
|
|
|
+ validationErrors,
|
|
|
|
|
+ (errors) => Object.keys(errors ?? {}).forEach((field) => unlockField(field)),
|
|
|
|
|
+ { deep: true },
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
const onPhotoSelected = (event) => {
|
|
const onPhotoSelected = (event) => {
|
|
|
const file = event.target.files?.[0];
|
|
const file = event.target.files?.[0];
|
|
|
event.target.value = "";
|
|
event.target.value = "";
|
|
@@ -231,7 +260,7 @@ const onPhotoSelected = (event) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const onSubmit = async () => {
|
|
const onSubmit = async () => {
|
|
|
- if (!photoFile.value) {
|
|
|
|
|
|
|
+ if (!photoFile.value && !photoPreview.value) {
|
|
|
photoError.value = t("auth.first_access.photo_required");
|
|
photoError.value = t("auth.first_access.photo_required");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -251,7 +280,7 @@ const onSubmit = async () => {
|
|
|
clearFirstAccessData();
|
|
clearFirstAccessData();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- await login(form.value.registration, password);
|
|
|
|
|
|
|
+ await login(form.value.registration, password, { skipSuccessNotify: true });
|
|
|
$q.notify({ type: "positive", message: t("auth.first_access.success") });
|
|
$q.notify({ type: "positive", message: t("auth.first_access.success") });
|
|
|
router.push({ name: "CarteirinhaPage" });
|
|
router.push({ name: "CarteirinhaPage" });
|
|
|
} catch {
|
|
} catch {
|
|
@@ -288,6 +317,8 @@ onBeforeMount(async () => {
|
|
|
if (photo_url) {
|
|
if (photo_url) {
|
|
|
photoPreview.value = photo_url;
|
|
photoPreview.value = photo_url;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ unlockInvalidFields();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|