Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useSchemaWebhook } from '../../hooks/useSchemaWebhook'
import { API_ATTRIBUTE } from '../../constants'
import { useTranslation } from 'react-i18next'
import { getErrorMessage } from '../../utils/errorHandler'
import type { ApiError } from '../../utils/errorHandler'
import { useAppNavigation, ROUTES } from '@/helpers/navigation'

function AttributeAddPage(): JSX.Element {
Expand All @@ -30,7 +31,7 @@ function AttributeAddPage(): JSX.Element {
queryClient.invalidateQueries({ queryKey: getGetAttributesQueryKey() })
navigateBack(ROUTES.ATTRIBUTES_LIST)
},
onError: (error: unknown) => {
onError: (error: Error | ApiError | Record<string, never>) => {
const errorMessage = getErrorMessage(error, 'errors.attribute_create_failed', t)
dispatch(updateToast(true, 'error', errorMessage))
},
Expand Down
21 changes: 7 additions & 14 deletions admin-ui/plugins/schema/components/Person/AttributeEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
AttributeItem,
SubmitData,
} from 'Plugins/schema/components/types/AttributeListPage.types'
import { getDefaultAttributeItem } from '../../utils/formHelpers'
import {
JansAttribute,
useGetAttributesByInum,
Expand Down Expand Up @@ -55,15 +56,17 @@ function AttributeEditPage(): JSX.Element {
queryClient.invalidateQueries({ queryKey: getGetAttributesQueryKey() })
queryClient.invalidateQueries({ queryKey: getGetAttributesByInumQueryKey(inum) })
},
onError: (error: unknown) => {
onError: (error: Error | Record<string, never>) => {
const errorMessage = getErrorMessage(error, 'errors.attribute_update_failed', t)
dispatch(updateToast(true, 'error', errorMessage))
},
},
})

const defaultAttribute = useMemo(() => getDefaultAttributeItem(), [])

const extensibleItems = useMemo(() => {
if (!attribute) return null
if (!attribute) return defaultAttribute
const cloned = cloneDeep(attribute) as JansAttribute

if (!cloned.attributeValidation) {
Expand All @@ -75,10 +78,10 @@ function AttributeEditPage(): JSX.Element {
}

return cloned
}, [attribute])
}, [attribute, defaultAttribute])

const customHandleSubmit = useCallback(
({ data, userMessage, modifiedFields, performedOn }: SubmitData): void => {
({ data, userMessage, modifiedFields }: SubmitData): void => {
if (data) {
putAttributeMutation.mutate(
{ data: data as JansAttribute },
Expand Down Expand Up @@ -112,16 +115,6 @@ function AttributeEditPage(): JSX.Element {
)
}

if (!extensibleItems) {
return (
<GluuLoader blocking={isLoading}>
<Card className="mb-3" style={applicationStyle.mainCard}>
<CardBody>{t('messages.loading_attribute')}</CardBody>
</Card>
</GluuLoader>
)
}

return (
<GluuLoader blocking={isLoading || putAttributeMutation.isPending}>
<Card className="mb-3" style={applicationStyle.mainCard}>
Expand Down
Loading
Loading