Skip to content

Commit 48c6453

Browse files
committed
fix(user-modal): integrate general settings query in user modal
1 parent 4ab9ea0 commit 48c6453

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

dashboard/src/components/dialogs/user-modal.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import useDirDetection from '@/hooks/use-dir-detection'
2222
import useDynamicErrorHandler from '@/hooks/use-dynamic-errors.ts'
2323
import { cn } from '@/lib/utils'
2424
import {
25+
getGeneralSettings,
26+
getGetGeneralSettingsQueryKey,
2527
getGetGroupsSimpleQueryKey,
2628
useCreateUser,
2729
useCreateUserFromTemplate,
@@ -39,7 +41,7 @@ import { parseDateInput } from '@/utils/dateTimeParsing'
3941
import { bytesToFormGigabytes, formatBytes, gbToBytes } from '@/utils/formatByte'
4042
import { invalidateUserMetricsQueries, upsertUserInUsersCache } from '@/utils/usersCache'
4143
import { generateWireGuardKeyPair, getWireGuardPublicKey } from '@/utils/wireguard'
42-
import { useQueryClient } from '@tanstack/react-query'
44+
import { useQuery, useQueryClient } from '@tanstack/react-query'
4345
import { CalendarClock, CalendarPlus, ChevronDown, EllipsisVertical, Info, Layers, Link2Off, ListStart, Lock, Network, PieChart, RefreshCcw, Group, Users, Pencil, UserRoundPlus } from 'lucide-react'
4446
import React, { useEffect, useState } from 'react'
4547
import { UseFormReturn } from 'react-hook-form'
@@ -492,6 +494,13 @@ function UserModal({ isDialogOpen, onOpenChange, form, editingUser, editingUserI
492494
},
493495
)
494496

497+
const { data: generalSettings } = useQuery({
498+
queryKey: getGetGeneralSettingsQueryKey(),
499+
queryFn: () => getGeneralSettings(),
500+
enabled: isDialogOpen,
501+
refetchOnMount: true,
502+
})
503+
495504
const syncUserCacheFromApiResponse = (user: UserResponse, options?: { allowInsert?: boolean; notifySuccessCallback?: boolean }) => {
496505
upsertUserInUsersCache(queryClient, user, { allowInsert: options?.allowInsert ?? false })
497506
invalidateUserMetricsQueries(queryClient)
@@ -2768,4 +2777,4 @@ function UserModal({ isDialogOpen, onOpenChange, form, editingUser, editingUserI
27682777
)
27692778
}
27702779

2771-
export default UserModal
2780+
export default UserModal

dashboard/src/pages/_dashboard.settings.general.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const generalSettingsSchema = z.object({
2424
})
2525

2626
type GeneralSettingsFormInput = z.input<typeof generalSettingsSchema>
27-
type GeneralSettingsStringField = 'default_flow' | 'default_method'
2827

2928
export default function General() {
3029
const { t } = useTranslation()
@@ -152,7 +151,7 @@ export default function General() {
152151
)
153152
}
154153

155-
const clearField = (field: GeneralSettingsStringField) => {
154+
const clearField = (field: keyof GeneralSettingsFormInput) => {
156155
return (e: React.MouseEvent<HTMLButtonElement>) => {
157156
e.preventDefault()
158157
e.stopPropagation()
@@ -231,7 +230,6 @@ export default function General() {
231230
)}
232231
/>
233232
</div>
234-
235233
</div>
236234

237235
<Separator className="my-3" />
@@ -292,4 +290,4 @@ export default function General() {
292290
</Form>
293291
</div>
294292
)
295-
}
293+
}

0 commit comments

Comments
 (0)