-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathJansLock.tsx
More file actions
63 lines (56 loc) · 2.07 KB
/
JansLock.tsx
File metadata and controls
63 lines (56 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useDispatch } from 'react-redux'
import { useQueryClient } from '@tanstack/react-query'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import { Card, CardBody } from 'Components'
import JansLockConfiguration from './JansLockConfiguration'
import {
useGetLockProperties,
usePatchLockProperties,
getGetLockPropertiesQueryKey,
} from 'JansConfigApi'
import { PatchOperation } from '../types'
import SetTitle from 'Utils/SetTitle'
import { updateToast } from 'Redux/features/toastSlice'
const JansLock: React.FC = () => {
const { t } = useTranslation()
const dispatch = useDispatch()
const queryClient = useQueryClient()
SetTitle(t('titles.jans_lock'))
const { data: lockConfiguration, isLoading } = useGetLockProperties()
const patchMutation = usePatchLockProperties({
mutation: {
onSuccess: () => {
dispatch(updateToast(true, 'success', t('messages.success_in_saving')))
queryClient.invalidateQueries({ queryKey: getGetLockPropertiesQueryKey() })
},
onError: (error: unknown) => {
const err = error as { response?: { data?: { message?: string } } }
const errorMessage = err?.response?.data?.message || t('messages.error_in_saving')
dispatch(updateToast(true, 'error', errorMessage))
},
},
})
const handleUpdate = (patchOperations: PatchOperation[]) => {
patchMutation.mutate({ data: patchOperations })
}
const loading = isLoading || patchMutation.isPending
return (
<GluuLoader blocking={loading}>
<Card className="mb-3" style={applicationStyle.mainCard}>
<CardBody>
{!isLoading && lockConfiguration ? (
<JansLockConfiguration
lockConfig={lockConfiguration as Record<string, unknown>}
onUpdate={handleUpdate}
isSubmitting={patchMutation.isPending}
/>
) : null}
</CardBody>
</Card>
</GluuLoader>
)
}
export default JansLock