mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(console): language editor form should be dirty on clear button clicked (#2037)
This commit is contained in:
parent
800ac7fcd9
commit
1223d23eb3
2 changed files with 10 additions and 5 deletions
|
@ -66,6 +66,7 @@ const LanguageEditor = () => {
|
|||
const {
|
||||
handleSubmit,
|
||||
reset,
|
||||
setValue,
|
||||
formState: { isSubmitting, isDirty, dirtyFields },
|
||||
} = formMethods;
|
||||
|
||||
|
@ -159,7 +160,11 @@ const LanguageEditor = () => {
|
|||
className={style.clearButton}
|
||||
icon={<Delete />}
|
||||
onClick={() => {
|
||||
reset(emptyUiTranslation);
|
||||
for (const [key, value] of Object.entries(
|
||||
flattenTranslation(emptyUiTranslation)
|
||||
)) {
|
||||
setValue(key, value, { shouldDirty: true });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
|
|
|
@ -110,14 +110,14 @@ export const flattenTranslation = (
|
|||
const unwrappedKey = `${prefix}${key}`;
|
||||
const unwrapped = translation[key];
|
||||
|
||||
return unwrapped
|
||||
? {
|
||||
return unwrapped === undefined
|
||||
? result
|
||||
: {
|
||||
...result,
|
||||
...(typeof unwrapped === 'string'
|
||||
? { [unwrappedKey]: unwrapped }
|
||||
: flattenTranslation(unwrapped, unwrappedKey)),
|
||||
}
|
||||
: result;
|
||||
};
|
||||
}, {});
|
||||
|
||||
const emptyTranslation = (translation: Translation): Translation =>
|
||||
|
|
Loading…
Reference in a new issue