Skip to content

Commit 81b4d20

Browse files
feat(admin): adding uniformity in cancel and back buttons present in User claims (#2485)
* back button uniform implementation in User claims * Code rabbit enhancements in User claims * Code rabbit enhancements in User claims * Code rabbit enhancements in User claims * Code rabbit enhancements in User claims * made user types optional as it was previously
1 parent e664cbb commit 81b4d20

File tree

13 files changed

+940
-577
lines changed

13 files changed

+940
-577
lines changed

admin-ui/plugins/schema/components/Person/AttributeAddPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useSchemaWebhook } from '../../hooks/useSchemaWebhook'
1313
import { API_ATTRIBUTE } from '../../constants'
1414
import { useTranslation } from 'react-i18next'
1515
import { getErrorMessage } from '../../utils/errorHandler'
16+
import type { ApiError } from '../../utils/errorHandler'
1617
import { useAppNavigation, ROUTES } from '@/helpers/navigation'
1718

1819
function AttributeAddPage(): JSX.Element {
@@ -30,7 +31,7 @@ function AttributeAddPage(): JSX.Element {
3031
queryClient.invalidateQueries({ queryKey: getGetAttributesQueryKey() })
3132
navigateBack(ROUTES.ATTRIBUTES_LIST)
3233
},
33-
onError: (error: unknown) => {
34+
onError: (error: Error | ApiError | Record<string, never>) => {
3435
const errorMessage = getErrorMessage(error, 'errors.attribute_create_failed', t)
3536
dispatch(updateToast(true, 'error', errorMessage))
3637
},

admin-ui/plugins/schema/components/Person/AttributeEditPage.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {
1111
AttributeItem,
1212
SubmitData,
1313
} from 'Plugins/schema/components/types/AttributeListPage.types'
14+
import { getDefaultAttributeItem } from '../../utils/formHelpers'
15+
import { DEFAULT_ATTRIBUTE_VALIDATION } from '../../helper/utils'
1416
import {
1517
JansAttribute,
1618
useGetAttributesByInum,
@@ -55,30 +57,28 @@ function AttributeEditPage(): JSX.Element {
5557
queryClient.invalidateQueries({ queryKey: getGetAttributesQueryKey() })
5658
queryClient.invalidateQueries({ queryKey: getGetAttributesByInumQueryKey(inum) })
5759
},
58-
onError: (error: unknown) => {
60+
onError: (error: Error | Record<string, never>) => {
5961
const errorMessage = getErrorMessage(error, 'errors.attribute_update_failed', t)
6062
dispatch(updateToast(true, 'error', errorMessage))
6163
},
6264
},
6365
})
6466

67+
const defaultAttribute = useMemo(() => getDefaultAttributeItem(), [])
68+
6569
const extensibleItems = useMemo(() => {
66-
if (!attribute) return null
70+
if (!attribute) return defaultAttribute
6771
const cloned = cloneDeep(attribute) as JansAttribute
6872

6973
if (!cloned.attributeValidation) {
70-
cloned.attributeValidation = {
71-
maxLength: undefined,
72-
regexp: undefined,
73-
minLength: undefined,
74-
}
74+
cloned.attributeValidation = { ...DEFAULT_ATTRIBUTE_VALIDATION }
7575
}
7676

7777
return cloned
78-
}, [attribute])
78+
}, [attribute, defaultAttribute])
7979

8080
const customHandleSubmit = useCallback(
81-
({ data, userMessage, modifiedFields, performedOn }: SubmitData): void => {
81+
({ data, userMessage, modifiedFields }: SubmitData): void => {
8282
if (data) {
8383
putAttributeMutation.mutate(
8484
{ data: data as JansAttribute },
@@ -112,16 +112,6 @@ function AttributeEditPage(): JSX.Element {
112112
)
113113
}
114114

115-
if (!extensibleItems) {
116-
return (
117-
<GluuLoader blocking={isLoading}>
118-
<Card className="mb-3" style={applicationStyle.mainCard}>
119-
<CardBody>{t('messages.loading_attribute')}</CardBody>
120-
</Card>
121-
</GluuLoader>
122-
)
123-
}
124-
125115
return (
126116
<GluuLoader blocking={isLoading || putAttributeMutation.isPending}>
127117
<Card className="mb-3" style={applicationStyle.mainCard}>

0 commit comments

Comments
 (0)