fix: admin courses
This commit is contained in:
@@ -295,23 +295,27 @@ const { data: profile } = useGetMeQuery()
|
||||
|
||||
watch(profile, (user) => {
|
||||
if (!user) return
|
||||
const nameParts = String(user.name || '').trim().split(/\s+/).filter(Boolean)
|
||||
const firstName = user.firstName || nameParts[0] || ''
|
||||
const lastName = user.lastName || nameParts.slice(1).join(' ') || ''
|
||||
const phone = user.phone || user.phoneNumber || ''
|
||||
form.value = {
|
||||
...form.value,
|
||||
firstName: user.firstName || '',
|
||||
lastName: user.lastName || '',
|
||||
firstName,
|
||||
lastName,
|
||||
birthDate: user.profile?.birthDate || '',
|
||||
nationalCode: user.nationalCode || '',
|
||||
maritalStatus: user.profile?.maritalStatus || '',
|
||||
gender: user.profile?.gender || '',
|
||||
bio: user.profile?.bio || '',
|
||||
phoneNumber: user.phoneNumber || '',
|
||||
phoneNumber: phone,
|
||||
provinceId: user.address?.province?.id || '',
|
||||
cityId: user.address?.city?.id || '',
|
||||
address: user.address?.address || '',
|
||||
avatarId: user.profile?.avatarId || null,
|
||||
}
|
||||
initialNationalCode.value = user.nationalCode || ''
|
||||
initialPhoneNumber.value = user.phoneNumber || ''
|
||||
initialPhoneNumber.value = phone
|
||||
if (user.avatarUrl) avatar.value = { url: user.avatarUrl }
|
||||
})
|
||||
|
||||
@@ -336,11 +340,21 @@ const updateMutation = useUpdateProfileMutation()
|
||||
const onSubmit = async () => {
|
||||
const { isValid, payload } = await validate(form.value)
|
||||
if (!isValid) return
|
||||
if (!payload.password) {
|
||||
delete payload.password
|
||||
delete payload.passwordConfirmation
|
||||
// Backend PATCH /me accepts: name, email, phone, password (+confirmation),
|
||||
// avatar_media_id. Other UI-only fields (province/city/address/birthDate/…)
|
||||
// are not in the backend Postman doc and are dropped here.
|
||||
const name = [payload.firstName, payload.lastName].filter(Boolean).join(' ').trim()
|
||||
const body = {
|
||||
...(name ? { name } : {}),
|
||||
...(payload.phoneNumber ? { phone: payload.phoneNumber } : {}),
|
||||
...(payload.email ? { email: payload.email } : {}),
|
||||
...(payload.avatarId ? { avatarMediaId: payload.avatarId } : {}),
|
||||
}
|
||||
await updateMutation.mutateAsync(payload)
|
||||
if (payload.password) {
|
||||
body.password = payload.password
|
||||
body.passwordConfirmation = payload.passwordConfirmation
|
||||
}
|
||||
await updateMutation.mutateAsync(body)
|
||||
await queryClient.invalidateQueries({ queryKey: authKeys.me() })
|
||||
toast.success('پروفایل با موفقیت بهروز شد')
|
||||
router.push({ name: 'student-dashboard' })
|
||||
|
||||
Reference in New Issue
Block a user