@@ -70,16 +70,25 @@ export const useGetRegistrationVideoQuery = (options = {}) =>
|
||||
|
||||
export const useUploadMediaMutation = () => useMutation({ mutationFn: apiUploadMedia })
|
||||
|
||||
// Register-data is a flat `{ field: value }` object; legacy responses were a
|
||||
// `[{ key, value }]` list. Normalize both into the object shape.
|
||||
const toRegisterDataObject = (response) => {
|
||||
const body = response?.data ?? response
|
||||
const raw = Array.isArray(body) ? body : body?.data ?? body
|
||||
if (Array.isArray(raw)) {
|
||||
return raw.reduce((acc, item) => {
|
||||
if (item && typeof item === 'object' && 'key' in item) acc[item.key] = item.value
|
||||
return acc
|
||||
}, {})
|
||||
}
|
||||
return raw && typeof raw === 'object' ? raw : {}
|
||||
}
|
||||
|
||||
export const useGetRegisterDataQuery = (options = {}) =>
|
||||
useQuery({
|
||||
queryKey: authKeys.registerData(),
|
||||
queryFn: () => apiGetRegisterData(),
|
||||
select: (response) => {
|
||||
const data = response?.data ?? response
|
||||
if (Array.isArray(data)) return data
|
||||
if (Array.isArray(data?.data)) return data.data
|
||||
return []
|
||||
},
|
||||
select: toRegisterDataObject,
|
||||
...options,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user