mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
feat(console): add change alert and save changes footer (#5492)
* feat(console): add change alert and save changes footer add change alert and save changes footer * chore(console): add useMemo hook add useMemo hook
This commit is contained in:
parent
c8eaa45417
commit
213d6f97a4
1 changed files with 27 additions and 5 deletions
|
@ -1,8 +1,11 @@
|
|||
import { withAppInsights } from '@logto/app-insights/react/AppInsightsReact';
|
||||
import classNames from 'classnames';
|
||||
import { useMemo } from 'react';
|
||||
import { useForm, FormProvider } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import SubmitFormChangesActionBar from '@/components/SubmitFormChangesActionBar';
|
||||
import UnsavedChangesAlertModal from '@/components/UnsavedChangesAlertModal';
|
||||
import CardTitle from '@/ds-components/CardTitle';
|
||||
import TabNav, { TabNavItem } from '@/ds-components/TabNav';
|
||||
|
||||
|
@ -43,6 +46,22 @@ function JwtClaims({ tab }: Props) {
|
|||
},
|
||||
});
|
||||
|
||||
const activeForm = useMemo(
|
||||
() =>
|
||||
tab === JwtTokenType.UserAccessToken ? userJwtClaimsForm : machineToMachineJwtClaimsForm,
|
||||
[machineToMachineJwtClaimsForm, tab, userJwtClaimsForm]
|
||||
);
|
||||
|
||||
const {
|
||||
formState: { isDirty, isSubmitting },
|
||||
reset,
|
||||
handleSubmit,
|
||||
} = activeForm;
|
||||
|
||||
const onSubmitHandler = handleSubmit(async (data) => {
|
||||
// TODO: API integration
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<CardTitle
|
||||
|
@ -57,16 +76,19 @@ function JwtClaims({ tab }: Props) {
|
|||
</TabNavItem>
|
||||
))}
|
||||
</TabNav>
|
||||
<FormProvider
|
||||
{...(tab === JwtTokenType.UserAccessToken
|
||||
? userJwtClaimsForm
|
||||
: machineToMachineJwtClaimsForm)}
|
||||
>
|
||||
<FormProvider {...activeForm}>
|
||||
<form className={classNames(styles.tabContent)}>
|
||||
<ScriptSection />
|
||||
<SettingsSection />
|
||||
</form>
|
||||
</FormProvider>
|
||||
<SubmitFormChangesActionBar
|
||||
isOpen={isDirty}
|
||||
isSubmitting={isSubmitting}
|
||||
onDiscard={reset}
|
||||
onSubmit={onSubmitHandler}
|
||||
/>
|
||||
<UnsavedChangesAlertModal hasUnsavedChanges={isDirty && !isSubmitting} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue