fix: admin courses
This commit is contained in:
@@ -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