fix: use mutation variables in onSuccess, fix null displayName handling
This commit is contained in:
@@ -72,13 +72,12 @@ export function AdminSettingsPage() {
|
|||||||
avatarType?: string | null
|
avatarType?: string | null
|
||||||
avatarStyle?: string | null
|
avatarStyle?: string | null
|
||||||
}) => apiClient.patch('admin/profile', params),
|
}) => apiClient.patch('admin/profile', params),
|
||||||
onSuccess: () => {
|
onSuccess: (_data, variables) => {
|
||||||
const name = profileForm.getValues('displayName').trim()
|
const p: UpdateProfileParams = { displayName: variables.displayName ?? null }
|
||||||
const p: UpdateProfileParams = { displayName: name.length ? name : null }
|
if (variables.avatar !== undefined) {
|
||||||
if (hasUnsavedPreview) {
|
p.avatar = variables.avatar
|
||||||
p.avatar = previewSrc
|
p.avatarType = variables.avatarType ?? null
|
||||||
p.avatarType = 'generated'
|
p.avatarStyle = variables.avatarStyle ?? null
|
||||||
p.avatarStyle = previewStyle
|
|
||||||
}
|
}
|
||||||
updateProfileFx(p)
|
updateProfileFx(p)
|
||||||
void qc.invalidateQueries({ queryKey: ['admin', 'profile'] })
|
void qc.invalidateQueries({ queryKey: ['admin', 'profile'] })
|
||||||
|
|||||||
Binary file not shown.
@@ -18,7 +18,8 @@ export async function registerAdminProfileRoutes(fastify) {
|
|||||||
fastify.patch('/api/admin/profile', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
|
fastify.patch('/api/admin/profile', { preHandler: [fastify.verifyAdmin] }, async (request, reply) => {
|
||||||
const userId = request.user.sub
|
const userId = request.user.sub
|
||||||
const nameRaw = request.body?.displayName
|
const nameRaw = request.body?.displayName
|
||||||
const displayName = nameRaw === null || nameRaw === undefined ? undefined : String(nameRaw).trim()
|
const displayName =
|
||||||
|
nameRaw === undefined ? undefined : nameRaw === null ? null : nameRaw === '' ? null : String(nameRaw).trim()
|
||||||
const avatarRaw = request.body?.avatar
|
const avatarRaw = request.body?.avatar
|
||||||
const avatar = avatarRaw === null || avatarRaw === undefined ? undefined : String(avatarRaw).trim()
|
const avatar = avatarRaw === null || avatarRaw === undefined ? undefined : String(avatarRaw).trim()
|
||||||
const avatarTypeRaw = request.body?.avatarType
|
const avatarTypeRaw = request.body?.avatarType
|
||||||
|
|||||||
Reference in New Issue
Block a user