fix: complete registration frontend flow
Deploy banu-front / deploy (push) Successful in 1m40s

This commit is contained in:
Server Migration
2026-08-15 17:28:40 +03:30
parent d94a96b25e
commit b64f528c0d
20 changed files with 431 additions and 158 deletions
@@ -145,6 +145,21 @@ const readPersisted = () => {
}
}
const normalizeCompletedSteps = (steps) =>
Array.isArray(steps) ? STUDENT_REGISTRATION_ORDER.filter((step) => steps.includes(step)) : []
const firstIncompleteIndex = (steps) => {
const index = STUDENT_REGISTRATION_ORDER.findIndex((step) => !steps.includes(step))
return index === -1 ? STUDENT_REGISTRATION_ORDER.length - 1 : index
}
const resolveCurrentStep = (candidate, completed) => {
const candidateIndex = STUDENT_REGISTRATION_ORDER.indexOf(candidate)
const reachableIndex = firstIncompleteIndex(completed)
if (candidateIndex >= 0 && candidateIndex <= reachableIndex) return candidate
return STUDENT_REGISTRATION_ORDER[reachableIndex]
}
export const useStudentRegistrationStore = defineStore('studentRegistration', () => {
const persisted = readPersisted() || {}
const initial = { ...emptyState(), ...persisted }
@@ -160,8 +175,8 @@ export const useStudentRegistrationStore = defineStore('studentRegistration', ()
const skill5 = ref({ ...emptyState().skill5, ...persisted.skill5 })
const skill6 = ref({ ...emptyState().skill6, ...persisted.skill6 })
const skill7 = ref({ ...emptyState().skill7, ...persisted.skill7 })
const currentStep = ref(initial.currentStep)
const completedSteps = ref(initial.completedSteps || [])
const completedSteps = ref(normalizeCompletedSteps(initial.completedSteps))
const currentStep = ref(resolveCurrentStep(initial.currentStep, completedSteps.value))
const registrationMedia = ref(initial.registrationMedia || {})
const sectionRefs = {
@@ -207,18 +222,33 @@ export const useStudentRegistrationStore = defineStore('studentRegistration', ()
)
const markStepAsCompleted = (stepKey) => {
if (!completedSteps.value.includes(stepKey)) {
if (STUDENT_REGISTRATION_ORDER.includes(stepKey) && !completedSteps.value.includes(stepKey)) {
completedSteps.value = [...completedSteps.value, stepKey]
}
}
const updateCurrentStep = (stepKey) => {
if (stepKey) currentStep.value = stepKey
if (canGoToStep(stepKey)) currentStep.value = stepKey
}
const updateSection = (section, value) => {
const target = sectionRefs[section]
if (!target || !value || typeof value !== 'object') return
target.value = { ...target.value, ...value }
}
const setRegistrationMedia = (value) => {
if (!value || typeof value !== 'object') return
registrationMedia.value = { ...registrationMedia.value, ...value }
}
const goToNextStep = () => {
const idx = STUDENT_REGISTRATION_ORDER.indexOf(currentStep.value)
if (idx >= 0 && idx < STUDENT_REGISTRATION_ORDER.length - 1) {
if (
idx >= 0 &&
idx < STUDENT_REGISTRATION_ORDER.length - 1 &&
completedSteps.value.includes(currentStep.value)
) {
currentStep.value = STUDENT_REGISTRATION_ORDER[idx + 1]
}
}
@@ -229,9 +259,8 @@ export const useStudentRegistrationStore = defineStore('studentRegistration', ()
}
const canGoToStep = (stepKey) => {
const currentIndex = STUDENT_REGISTRATION_ORDER.indexOf(currentStep.value)
const targetIndex = STUDENT_REGISTRATION_ORDER.indexOf(stepKey)
return targetIndex <= currentIndex + 1
return targetIndex >= 0 && targetIndex <= firstIncompleteIndex(completedSteps.value)
}
const buildCompletePayload = () => ({
@@ -307,6 +336,8 @@ export const useStudentRegistrationStore = defineStore('studentRegistration', ()
registrationMedia,
markStepAsCompleted,
updateCurrentStep,
updateSection,
setRegistrationMedia,
goToNextStep,
goToPrevStep,
canGoToStep,