diff --git a/packages/console/src/components/PermissionsTable/EditPermissionModal.tsx b/packages/console/src/components/EditScopeModal/index.tsx similarity index 55% rename from packages/console/src/components/PermissionsTable/EditPermissionModal.tsx rename to packages/console/src/components/EditScopeModal/index.tsx index 040a1e303..4d92e2eaf 100644 --- a/packages/console/src/components/PermissionsTable/EditPermissionModal.tsx +++ b/packages/console/src/components/EditScopeModal/index.tsx @@ -1,4 +1,5 @@ -import { type ScopeResponse } from '@logto/schemas'; +import { type AdminConsoleKey } from '@logto/phrases'; +import { type Nullable } from '@silverhand/essentials'; import { useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import ReactModal from 'react-modal'; @@ -10,24 +11,43 @@ import TextInput from '@/ds-components/TextInput'; import * as modalStyles from '@/scss/modal.module.scss'; import { trySubmitSafe } from '@/utils/form'; -type Props = { - data: ScopeResponse; - onClose: () => void; - onSubmit: (scope: ScopeResponse) => Promise; +export type EditScopeData = { + /** Only `description` is editable for all kinds of scopes */ + description: Nullable; }; -function EditPermissionModal({ data, onClose, onSubmit }: Props) { +type Props = { + /** The scope name displayed in the name input field */ + scopeName: string; + /** The data to edit */ + data: EditScopeData; + /** Determines the translation keys for texts in the editor modal */ + text: { + /** The translation key of the modal title */ + title: AdminConsoleKey; + /** The field name translation key for the name input */ + nameField: AdminConsoleKey; + /** The field name translation key for the description input */ + descriptionField: AdminConsoleKey; + /** The placeholder translation key for the description input */ + descriptionPlaceholder: AdminConsoleKey; + }; + onSubmit: (editedData: EditScopeData) => Promise; + onClose: () => void; +}; + +function EditScopeModal({ scopeName, data, text, onClose, onSubmit }: Props) { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { handleSubmit, register, formState: { isSubmitting }, - } = useForm({ defaultValues: data }); + } = useForm({ defaultValues: data }); const onSubmitHandler = handleSubmit( trySubmitSafe(async (formData) => { - await onSubmit({ ...data, ...formData }); + await onSubmit(formData); onClose(); }) ); @@ -43,7 +63,7 @@ function EditPermissionModal({ data, onClose, onSubmit }: Props) { }} >