fix: admin courses
This commit is contained in:
@@ -91,7 +91,11 @@ const redirectAfterLogin = useRedirectAfterLogin()
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
const response = await loginMutation.mutateAsync(payload)
|
||||
const response = await loginMutation.mutateAsync({
|
||||
phone: payload.phoneNumber,
|
||||
password: payload.password,
|
||||
deviceName: 'web',
|
||||
})
|
||||
applySession(response?.data ?? response)
|
||||
redirectAfterLogin()
|
||||
}
|
||||
|
||||
@@ -114,7 +114,13 @@ const { savePhoneNumber } = useAuth()
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
await registerMutation.mutateAsync(payload)
|
||||
const name = [payload.firstName, payload.lastName].filter(Boolean).join(' ').trim()
|
||||
await registerMutation.mutateAsync({
|
||||
name,
|
||||
phone: payload.phoneNumber,
|
||||
password: payload.password,
|
||||
passwordConfirmation: payload.passwordConfirmation,
|
||||
})
|
||||
savePhoneNumber(payload.phoneNumber)
|
||||
emit('next', { phoneNumber: payload.phoneNumber })
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
</div>
|
||||
|
||||
<div class="educational-info__divider" />
|
||||
<StepActions @back="store.goToPrevStep()" />
|
||||
<StepActions :loading="saveRegisterMutation.isPending.value" @back="store.goToPrevStep()" />
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -108,9 +108,13 @@ import TextField from '@/components/form/TextField.vue'
|
||||
import SelectField from '@/components/form/SelectField.vue'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import TextareaField from '@/components/form/TextareaField.vue'
|
||||
import { useSaveRegisterDataMutation } from '@/services/query/auth'
|
||||
import StepActions from '@/features/auth/components/studentRegister/StepActions.vue'
|
||||
import { educationalInformationSchema } from '@/features/auth/schema/student-register'
|
||||
import { useStudentRegistrationStore } from '@/features/auth/store/student-registration'
|
||||
import {
|
||||
toKeyValueList,
|
||||
useStudentRegistrationStore,
|
||||
} from '@/features/auth/store/student-registration'
|
||||
import { EDUCATION_STATUS, SEMINARY_LEVEL, STUDENT_REGISTRATION, UNIVERSITY_LEVEL } from '@/enums'
|
||||
|
||||
const store = useStudentRegistrationStore()
|
||||
@@ -139,9 +143,12 @@ const form = ref({ ...store.educational })
|
||||
|
||||
const { validate, validateAt, errors } = useYup(educationalInformationSchema)
|
||||
|
||||
const saveRegisterMutation = useSaveRegisterDataMutation()
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
await saveRegisterMutation.mutateAsync(toKeyValueList(payload))
|
||||
store.educational = { ...store.educational, ...payload }
|
||||
store.markStepAsCompleted(STUDENT_REGISTRATION.EDUCATIONAL_INFORMATION)
|
||||
store.goToNextStep()
|
||||
|
||||
@@ -92,6 +92,7 @@ const props = defineProps({
|
||||
maxSeconds: { type: Number, default: 120 },
|
||||
context: { type: String, default: 'verification' },
|
||||
subType: { type: String, default: '' },
|
||||
purpose: { type: String, default: '' },
|
||||
error: { type: String, default: '' },
|
||||
})
|
||||
|
||||
@@ -191,6 +192,7 @@ const handleStop = async () => {
|
||||
file,
|
||||
subType: props.subType || props.kind,
|
||||
context: props.context,
|
||||
...(props.purpose ? { purpose: props.purpose } : {}),
|
||||
})
|
||||
const response = await uploadMutation.mutateAsync(fd)
|
||||
const payload = response?.data ?? response
|
||||
@@ -276,7 +278,6 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
|
||||
&__media--audio {
|
||||
width: 100%;
|
||||
height: 2.5rem;
|
||||
background: transparent;
|
||||
position: absolute;
|
||||
|
||||
@@ -151,7 +151,10 @@
|
||||
|
||||
<div class="personal-info__divider" />
|
||||
|
||||
<StepActions :show-back="false" :loading="uploadMutation.isPending.value" />
|
||||
<StepActions
|
||||
:show-back="false"
|
||||
:loading="uploadMutation.isPending.value || saveRegisterMutation.isPending.value"
|
||||
/>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -167,13 +170,14 @@ import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import ImageCropper from '@/components/form/ImageCropper.vue'
|
||||
import { objectToFormData } from '@/utils/object-to-formdata'
|
||||
import TextareaField from '@/components/form/TextareaField.vue'
|
||||
import { useUploadMediaMutation } from '@/services/query/auth'
|
||||
import DatePickerField from '@/components/form/DatePickerField.vue'
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { GENDER, MARITAL_STATUS, STUDENT_REGISTRATION } from '@/enums'
|
||||
import { toKeyValueList } from '@/features/auth/store/student-registration'
|
||||
import { personalInformationSchema } from '@/features/auth/schema/student-register'
|
||||
import StepActions from '@/features/auth/components/studentRegister/StepActions.vue'
|
||||
import { useStudentRegistrationStore } from '@/features/auth/store/student-registration'
|
||||
import { useSaveRegisterDataMutation, useUploadMediaMutation } from '@/services/query/auth'
|
||||
import { useGetCitiesOfProvinceQuery, useGetProvincesQuery } from '@/services/query/common'
|
||||
|
||||
const store = useStudentRegistrationStore()
|
||||
@@ -202,7 +206,9 @@ const maxBirthDate = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
const initialPhoneNumber = ref(user.value?.phoneNumber || store.personal.phoneNumber || '')
|
||||
const initialPhoneNumber = ref(
|
||||
user.value?.phone || user.value?.phoneNumber || store.personal.phoneNumber || ''
|
||||
)
|
||||
|
||||
const form = ref({
|
||||
firstName: store.personal.firstName || '',
|
||||
@@ -246,7 +252,7 @@ const uploadMutation = useUploadMediaMutation()
|
||||
|
||||
const onAvatarCropped = async (file) => {
|
||||
try {
|
||||
const fd = objectToFormData({ file, subType: 'avatar', context: 'verification' })
|
||||
const fd = objectToFormData({ file, purpose: 'avatar', context: 'verification' })
|
||||
const response = await uploadMutation.mutateAsync(fd)
|
||||
const payload = response?.data ?? response
|
||||
const value = { url: payload?.url, uploadId: payload?.uploadId || payload?.id, ...payload }
|
||||
@@ -260,10 +266,14 @@ const onAvatarCropped = async (file) => {
|
||||
|
||||
const onAvatarError = (msg) => toast.error(msg)
|
||||
|
||||
const saveRegisterMutation = useSaveRegisterDataMutation()
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
store.personal = { ...store.personal, ...payload, avatar: form.value.avatar }
|
||||
const next = { ...payload, avatar: form.value.avatar }
|
||||
await saveRegisterMutation.mutateAsync(toKeyValueList(next))
|
||||
store.personal = { ...store.personal, ...next }
|
||||
store.markStepAsCompleted(STUDENT_REGISTRATION.PERSONAL_INFORMATION)
|
||||
store.goToNextStep()
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
</div>
|
||||
|
||||
<div class="professional-info__divider" />
|
||||
<StepActions @back="store.goToPrevStep()" />
|
||||
<StepActions :loading="saveRegisterMutation.isPending.value" @back="store.goToPrevStep()" />
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -114,9 +114,13 @@ import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import TextareaField from '@/components/form/TextareaField.vue'
|
||||
import { PROPAGATION_PLATFORM, STUDENT_REGISTRATION } from '@/enums'
|
||||
import { useSaveRegisterDataMutation } from '@/services/query/auth'
|
||||
import StepActions from '@/features/auth/components/studentRegister/StepActions.vue'
|
||||
import { professionalInformationSchema } from '@/features/auth/schema/student-register'
|
||||
import { useStudentRegistrationStore } from '@/features/auth/store/student-registration'
|
||||
import {
|
||||
toKeyValueList,
|
||||
useStudentRegistrationStore,
|
||||
} from '@/features/auth/store/student-registration'
|
||||
|
||||
const store = useStudentRegistrationStore()
|
||||
|
||||
@@ -167,6 +171,8 @@ const onPlatformsChange = (selected) => {
|
||||
|
||||
const { validate, validateAt, errors } = useYup(professionalInformationSchema)
|
||||
|
||||
const saveRegisterMutation = useSaveRegisterDataMutation()
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
@@ -181,12 +187,14 @@ const onSubmit = async () => {
|
||||
return { platform, platformDetails: '' }
|
||||
})
|
||||
|
||||
store.professional = {
|
||||
const next = {
|
||||
propagationExperienceYears: Number(payload.propagationExperienceYears),
|
||||
propagationMethodDescription: payload.propagationMethodDescription,
|
||||
specializedTopics: payload.specializedTopics,
|
||||
propagationPlatforms,
|
||||
}
|
||||
await saveRegisterMutation.mutateAsync(toKeyValueList(next))
|
||||
store.professional = next
|
||||
store.markStepAsCompleted(STUDENT_REGISTRATION.PROFESSIONAL_INFORMATION)
|
||||
store.goToNextStep()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
kind="audio"
|
||||
sub-type="audio"
|
||||
context="verification"
|
||||
purpose="voice"
|
||||
:max-seconds="180"
|
||||
:error="errors.faithProductionAudio"
|
||||
@uploaded="onUploaded"
|
||||
@@ -28,20 +29,23 @@
|
||||
</div>
|
||||
|
||||
<div class="skill-six__divider" />
|
||||
<StepActions @back="store.goToPrevStep()" />
|
||||
<StepActions :loading="saveRegisterMutation.isPending.value" @back="store.goToPrevStep()" />
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import useYup from '@/composables/useYup'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { STUDENT_REGISTRATION } from '@/enums'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import { useGetRegistrationVideoQuery } from '@/services/query/auth'
|
||||
import { useSaveRegisterDataMutation } from '@/services/query/auth'
|
||||
import StepActions from '@/features/auth/components/studentRegister/StepActions.vue'
|
||||
import { skillAssessmentPart6Schema } from '@/features/auth/schema/student-register'
|
||||
import MediaRecorder from '@/features/auth/components/studentRegister/MediaRecorder.vue'
|
||||
import { useStudentRegistrationStore } from '@/features/auth/store/student-registration'
|
||||
import {
|
||||
toKeyValueList,
|
||||
useStudentRegistrationStore,
|
||||
} from '@/features/auth/store/student-registration'
|
||||
|
||||
const store = useStudentRegistrationStore()
|
||||
|
||||
@@ -59,20 +63,14 @@ const onUploaded = (value) => {
|
||||
form.value.faithProductionId = value?.uploadId || ''
|
||||
}
|
||||
|
||||
const { data: media } = useGetRegistrationVideoQuery()
|
||||
const videoUrl = computed(() => store.registrationMedia.faithProductionVideoUrl || '')
|
||||
|
||||
const videoUrl = computed(
|
||||
() =>
|
||||
media.value?.faithProductionVideoUrl || store.registrationMedia.faithProductionVideoUrl || ''
|
||||
)
|
||||
|
||||
watch(media, (val) => {
|
||||
if (val) store.registrationMedia = { ...store.registrationMedia, ...val }
|
||||
})
|
||||
const saveRegisterMutation = useSaveRegisterDataMutation()
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
await saveRegisterMutation.mutateAsync(toKeyValueList(payload))
|
||||
store.skill6 = { ...store.skill6, ...payload }
|
||||
store.markStepAsCompleted(STUDENT_REGISTRATION.SKILL_ASSESSMENT_PART_6)
|
||||
store.goToNextStep()
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
<div class="skill-seven__divider" />
|
||||
<StepActions
|
||||
:loading="completeMutation.isPending.value"
|
||||
:loading="saveRegisterMutation.isPending.value"
|
||||
next-text="تایید اطلاعات"
|
||||
@back="store.goToPrevStep()"
|
||||
/>
|
||||
@@ -39,18 +39,19 @@
|
||||
<script setup>
|
||||
import { toast } from 'vue3-toastify'
|
||||
import useYup from '@/composables/useYup'
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import useAuth from '@/composables/useAuth'
|
||||
import { computed, ref } from 'vue'
|
||||
import { STUDENT_REGISTRATION } from '@/enums'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import StepActions from '@/features/auth/components/studentRegister/StepActions.vue'
|
||||
import { skillAssessmentPart7Schema } from '@/features/auth/schema/student-register'
|
||||
import MediaRecorder from '@/features/auth/components/studentRegister/MediaRecorder.vue'
|
||||
import { useStudentRegistrationStore } from '@/features/auth/store/student-registration'
|
||||
import { useCompleteProfileMutation, useGetRegistrationVideoQuery } from '@/services/query/auth'
|
||||
import {
|
||||
toKeyValueList,
|
||||
useStudentRegistrationStore,
|
||||
} from '@/features/auth/store/student-registration'
|
||||
import { useSaveRegisterDataMutation } from '@/services/query/auth'
|
||||
|
||||
const store = useStudentRegistrationStore()
|
||||
const { applySession } = useAuth()
|
||||
|
||||
const video = ref(store.skill7.leaderMessageVideo || null)
|
||||
|
||||
@@ -66,28 +67,17 @@ const onUploaded = (value) => {
|
||||
form.value.leaderMessageId = value?.uploadId || ''
|
||||
}
|
||||
|
||||
const { data: media } = useGetRegistrationVideoQuery()
|
||||
const videoUrl = computed(() => store.registrationMedia.leaderMessageVideoUrl || '')
|
||||
|
||||
const videoUrl = computed(
|
||||
() => media.value?.leaderMessageVideoUrl || store.registrationMedia.leaderMessageVideoUrl || ''
|
||||
)
|
||||
|
||||
watch(media, (val) => {
|
||||
if (val) store.registrationMedia = { ...store.registrationMedia, ...val }
|
||||
})
|
||||
|
||||
const completeMutation = useCompleteProfileMutation()
|
||||
const saveRegisterMutation = useSaveRegisterDataMutation()
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
store.skill7 = { ...store.skill7, ...payload }
|
||||
store.markStepAsCompleted(STUDENT_REGISTRATION.SKILL_ASSESSMENT_PART_7)
|
||||
|
||||
try {
|
||||
const response = await completeMutation.mutateAsync(store.buildCompletePayload())
|
||||
const data = response?.data ?? response
|
||||
applySession(data)
|
||||
await saveRegisterMutation.mutateAsync(toKeyValueList(payload))
|
||||
store.skill7 = { ...store.skill7, ...payload }
|
||||
store.markStepAsCompleted(STUDENT_REGISTRATION.SKILL_ASSESSMENT_PART_7)
|
||||
store.isProfileCompleted = true
|
||||
} catch (error) {
|
||||
toast.error(error?.response?.data?.message || 'عملیات با خطا مواجه شد')
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</div>
|
||||
|
||||
<div class="skill-step__divider" />
|
||||
<StepActions @back="store.goToPrevStep()" />
|
||||
<StepActions :loading="saveRegisterMutation.isPending.value" @back="store.goToPrevStep()" />
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -44,8 +44,12 @@ import SelectField from '@/components/form/SelectField.vue'
|
||||
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import TextareaField from '@/components/form/TextareaField.vue'
|
||||
import { useSaveRegisterDataMutation } from '@/services/query/auth'
|
||||
import StepActions from '@/features/auth/components/studentRegister/StepActions.vue'
|
||||
import { useStudentRegistrationStore } from '@/features/auth/store/student-registration'
|
||||
import {
|
||||
toKeyValueList,
|
||||
useStudentRegistrationStore,
|
||||
} from '@/features/auth/store/student-registration'
|
||||
|
||||
const props = defineProps({
|
||||
step: { type: Number, required: true },
|
||||
@@ -80,9 +84,12 @@ const onSelect = () => {
|
||||
|
||||
const { validate, errors } = useYup(props.schema)
|
||||
|
||||
const saveRegisterMutation = useSaveRegisterDataMutation()
|
||||
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
await saveRegisterMutation.mutateAsync(toKeyValueList(payload))
|
||||
store[props.storeKey] = { ...store[props.storeKey], ...payload }
|
||||
store.markStepAsCompleted(props.step)
|
||||
store.goToNextStep()
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
v-model="form.phoneNumber"
|
||||
name="phoneNumber"
|
||||
label="شماره موبایل"
|
||||
:disabled="!!user?.phoneNumber"
|
||||
:disabled="!!(user?.phone || user?.phoneNumber)"
|
||||
>
|
||||
<template #appendIcon>
|
||||
<SvgIcon name="phone" :size="22" color="var(--color-thd-gray)" />
|
||||
@@ -71,7 +71,7 @@ const redirectAfterLogin = useRedirectAfterLogin()
|
||||
const schema = resetPasswordSchema
|
||||
|
||||
const form = ref({
|
||||
phoneNumber: user.value?.phoneNumber || '',
|
||||
phoneNumber: user.value?.phone || user.value?.phoneNumber || '',
|
||||
password: '',
|
||||
passwordConfirmation: '',
|
||||
})
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
import useModal from '@/composables/useModal'
|
||||
import { computed, markRaw, watch } from 'vue'
|
||||
import { STUDENT_REGISTRATION } from '@/enums'
|
||||
import { useGetRegisterDataQuery } from '@/services/query/auth'
|
||||
import SideBarSteps from '@/features/auth/components/studentRegister/SideBarSteps.vue'
|
||||
import SuccessModal from '@/features/auth/components/studentRegister/SuccessModal.vue'
|
||||
import { useStudentRegistrationStore } from '@/features/auth/store/student-registration'
|
||||
@@ -40,6 +41,15 @@ import ProfessionalInformation from '@/features/auth/components/studentRegister/
|
||||
const store = useStudentRegistrationStore()
|
||||
const { isModal, openModal } = useModal()
|
||||
|
||||
const { data: registerData } = useGetRegisterDataQuery()
|
||||
watch(
|
||||
registerData,
|
||||
(list) => {
|
||||
if (Array.isArray(list) && list.length > 0) store.hydrateFromKeyValueList(list)
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
const STEP_TO_COMPONENT = {
|
||||
[STUDENT_REGISTRATION.PERSONAL_INFORMATION]: markRaw(PersonalInformation),
|
||||
[STUDENT_REGISTRATION.EDUCATIONAL_INFORMATION]: markRaw(EducationalInformation),
|
||||
|
||||
@@ -9,7 +9,7 @@ const requiredString = (min = 0) => {
|
||||
}
|
||||
|
||||
export const personalInformationSchema = object().shape({
|
||||
avatar: mixed().required(),
|
||||
avatar: mixed().notRequired(),
|
||||
avatarId: mixed().notRequired(),
|
||||
firstName: requiredString(3),
|
||||
lastName: requiredString(3),
|
||||
|
||||
@@ -69,6 +69,65 @@ const emptyState = () => ({
|
||||
registrationMedia: {},
|
||||
})
|
||||
|
||||
// Each field is owned by exactly one section. Used to route GET /me/register-data
|
||||
// values back into the matching slice on hydration.
|
||||
const SECTION_FIELDS = {
|
||||
personal: [
|
||||
'avatar',
|
||||
'avatarId',
|
||||
'firstName',
|
||||
'lastName',
|
||||
'birthDate',
|
||||
'nationalCode',
|
||||
'maritalStatus',
|
||||
'gender',
|
||||
'phoneNumber',
|
||||
'provinceId',
|
||||
'cityId',
|
||||
'address',
|
||||
],
|
||||
educational: [
|
||||
'educationStatus',
|
||||
'seminaryLevel',
|
||||
'universityLevel',
|
||||
'universityName',
|
||||
'fieldOfStudy',
|
||||
'workExperienceSummary',
|
||||
'activitySummary',
|
||||
],
|
||||
professional: [
|
||||
'propagationExperienceYears',
|
||||
'propagationMethodDescription',
|
||||
'specializedTopics',
|
||||
'propagationPlatforms',
|
||||
],
|
||||
skill1: ['responseToLowSatisfaction', 'responseToLowSatisfactionDescription'],
|
||||
skill2: ['responseToSessionCancellation', 'responseToSessionCancellationDescription'],
|
||||
skill3: ['responseToAudienceConflict', 'responseToAudienceConflictDescription'],
|
||||
skill4: ['responseToCompetingPropagator', 'responseToCompetingPropagatorDescription'],
|
||||
skill5: ['responseToUnqualifiedAdvisors', 'relevantCertificates', 'hijabApproach'],
|
||||
skill6: ['faithProductionAudio', 'faithProductionId'],
|
||||
skill7: ['leaderMessageVideo', 'leaderMessageId'],
|
||||
}
|
||||
|
||||
const FIELD_TO_SECTION = Object.entries(SECTION_FIELDS).reduce((acc, [section, fields]) => {
|
||||
fields.forEach((field) => {
|
||||
acc[field] = section
|
||||
})
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
export const toKeyValueList = (obj = {}) =>
|
||||
Object.entries(obj).map(([key, value]) => ({ key, value }))
|
||||
|
||||
export const fromKeyValueList = (list = []) => {
|
||||
if (!Array.isArray(list)) return {}
|
||||
return list.reduce((acc, item) => {
|
||||
if (item && typeof item === 'object' && 'key' in item) acc[item.key] = item.value
|
||||
return acc
|
||||
}, {})
|
||||
}
|
||||
|
||||
const readPersisted = () => {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
@@ -98,6 +157,19 @@ export const useStudentRegistrationStore = defineStore('studentRegistration', ()
|
||||
const completedSteps = ref(initial.completedSteps || [])
|
||||
const registrationMedia = ref(initial.registrationMedia || {})
|
||||
|
||||
const sectionRefs = {
|
||||
personal,
|
||||
educational,
|
||||
professional,
|
||||
skill1,
|
||||
skill2,
|
||||
skill3,
|
||||
skill4,
|
||||
skill5,
|
||||
skill6,
|
||||
skill7,
|
||||
}
|
||||
|
||||
const snapshot = computed(() => ({
|
||||
isProfileCompleted: isProfileCompleted.value,
|
||||
personal: personal.value,
|
||||
@@ -171,6 +243,22 @@ export const useStudentRegistrationStore = defineStore('studentRegistration', ()
|
||||
: personal.value.avatarId,
|
||||
})
|
||||
|
||||
// Take the flat `{key,value}` list from GET /me/register-data and slot each
|
||||
// value into the right section ref, leaving anything we don't recognise alone.
|
||||
const hydrateFromKeyValueList = (list) => {
|
||||
const flat = fromKeyValueList(list)
|
||||
const buckets = {}
|
||||
Object.entries(flat).forEach(([key, value]) => {
|
||||
const section = FIELD_TO_SECTION[key]
|
||||
if (!section) return
|
||||
buckets[section] = { ...(buckets[section] || {}), [key]: value }
|
||||
})
|
||||
Object.entries(buckets).forEach(([section, patch]) => {
|
||||
const target = sectionRefs[section]
|
||||
if (target) target.value = { ...target.value, ...patch }
|
||||
})
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
const fresh = emptyState()
|
||||
isProfileCompleted.value = fresh.isProfileCompleted
|
||||
@@ -215,6 +303,7 @@ export const useStudentRegistrationStore = defineStore('studentRegistration', ()
|
||||
goToPrevStep,
|
||||
canGoToStep,
|
||||
buildCompletePayload,
|
||||
hydrateFromKeyValueList,
|
||||
reset,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user