diff --git a/databox/client/src/components/Dialog/Collection/EditCollection.tsx b/databox/client/src/components/Dialog/Collection/EditCollection.tsx
index 5a2c7fb85..14dd8d6e3 100644
--- a/databox/client/src/components/Dialog/Collection/EditCollection.tsx
+++ b/databox/client/src/components/Dialog/Collection/EditCollection.tsx
@@ -1,5 +1,5 @@
import {Collection} from '../../../types';
-import {putCollection} from '../../../api/collection';
+import {clearWorkspaceCache, postCollection, putCollection} from '../../../api/collection';
import {useTranslation} from 'react-i18next';
import {toast} from 'react-toastify';
import {useFormSubmit} from '@alchemy/api';
@@ -17,7 +17,11 @@ type Props = {
export default function EditCollection({data, onClose, minHeight}: Props) {
const {t} = useTranslation();
- const {submitting, submitted, handleSubmit, errors} = useFormSubmit({
+ const usedFormSubmit = useFormSubmit({
+ defaultValues: {
+ title: '',
+ privacy: 0,
+ },
onSubmit: async (data: Collection) => {
return await putCollection(data.id, data);
},
@@ -32,6 +36,11 @@ export default function EditCollection({data, onClose, minHeight}: Props) {
},
});
+ const {
+ submitting,
+ remoteErrors,
+ } = usedFormSubmit;
+
const formId = 'edit-collection';
return (
@@ -39,15 +48,13 @@ export default function EditCollection({data, onClose, minHeight}: Props) {
onClose={onClose}
formId={formId}
loading={submitting}
- errors={errors}
+ errors={remoteErrors}
minHeight={minHeight}
>
);
diff --git a/databox/client/src/components/Dialog/Workspace/DefinitionManager.tsx b/databox/client/src/components/Dialog/Workspace/DefinitionManager.tsx
index fb2dd9a31..f516a0491 100644
--- a/databox/client/src/components/Dialog/Workspace/DefinitionManager.tsx
+++ b/databox/client/src/components/Dialog/Workspace/DefinitionManager.tsx
@@ -21,7 +21,7 @@ import {ApiHydraObjectResponse} from '../../../api/hydra';
import DialogActions from '@mui/material/DialogActions';
import {useTranslation} from 'react-i18next';
import AddBoxIcon from '@mui/icons-material/AddBox';
-import useFormSubmit, {UseFormHandleSubmit} from '../../../hooks/useFormSubmit';
+import {useFormSubmit} from '@alchemy/api';
import {LoadingButton} from '@mui/lab';
import {toast} from 'react-toastify';
import RemoteErrors from '../../Form/RemoteErrors';
@@ -30,17 +30,18 @@ import SortableList, {
SortableItem,
SortableItemProps,
} from '../../Ui/Sortable/SortableList';
+import {UseFormSubmit} from '@alchemy/api';
+import {FieldValues} from "react-hook-form";
-type DefinitionBase = ApiHydraObjectResponse & {id: string};
+type DefinitionBase = ApiHydraObjectResponse & { id: string };
export type DefinitionItemProps = {
data: D;
};
-export type DefinitionItemFormProps = {
+export type DefinitionItemFormProps = {
formId: string;
- handleSubmit: UseFormHandleSubmit;
- submitting: boolean;
+ usedFormSubmit: UseFormSubmit;
workspaceId: string;
} & DefinitionItemProps;
@@ -65,19 +66,17 @@ const SortableListItem = React.memo(
} & SortableItemProps) => {
const {selectedItem, onClick, listComponent} = itemProps;
- return (
-
-
- {React.createElement(listComponent, {
- data,
- key: data.id,
- })}
-
-
- );
+ return
+
+ {React.createElement(listComponent, {
+ data,
+ key: data.id,
+ })}
+
+
}
);
@@ -151,7 +150,8 @@ export default function DefinitionManager({
});
}, []);
- const {submitting, handleSubmit, errors} = useFormSubmit({
+ const usedFormSubmit = useFormSubmit({
+
onSubmit: async (data: D) => {
const newData = await handleSave(data);
@@ -185,6 +185,12 @@ export default function DefinitionManager({
},
});
+ const {
+ submitting,
+ handleSubmit,
+ remoteErrors
+ } = usedFormSubmit;
+
const onDelete = useCallback(() => {
if (handleDelete && typeof item === 'object') {
if (
@@ -231,159 +237,148 @@ export default function DefinitionManager({
};
}, [onSort, handleItemClick, item, listComponent]);
- return (
- <>
-
+
+ ({
display: 'flex',
- flex: '1 1 auto',
- minHeight,
- }}
- style={{
- padding: 0,
- }}
+ overflowY: 'auto',
+ borderRight: `1px solid ${theme.palette.divider}`,
+ })}
>
- ({
- display: 'flex',
- overflowY: 'auto',
- borderRight: `1px solid ${theme.palette.divider}`,
- })}
+
-
-
-
-
-
-
-
-
-
-
-
- {onSort && list && (
-
- list={
- list as (D &
- SortableItem &
- DefinitionBase)[]
- }
- onOrderChange={onOrderChange}
- itemComponent={SortableListItem}
- itemProps={itemProps!}
- />
- )}
+
+
+
+
+
+
+
+
+
- {!onSort &&
- list &&
- list.map(i => {
- return (
-
-
- {React.createElement(
- listComponent,
- {
- data: i,
- key: i.id,
- }
- )}
-
-
- );
- })}
+ {onSort && list && (
+
+ list={
+ list as (D &
+ SortableItem &
+ DefinitionBase)[]
+ }
+ onOrderChange={onOrderChange}
+ itemComponent={SortableListItem}
+ itemProps={itemProps!}
+ />
+ )}
- {!list &&
- [0, 1, 2].map(i => (
-
-
-
-
- }
- secondary={
-
+ {!onSort &&
+ list &&
+ list.map(i => {
+ return
+
+ {React.createElement(
+ listComponent,
+ {
+ data: i,
+ key: i.id,
}
- />
-
- ))}
-
-
-
- {item &&
- React.createElement(itemComponent, {
- data:
- item === 'new' ? (createNewItem() as D) : item!,
- key: item === 'new' ? 'new' : item!.id,
- formId,
- handleSubmit,
- submitting,
- workspaceId,
+ )}
+
+
})}
-
- {item && item !== 'new' && handleDelete && (
- <>
-
-
- >
- )}
-
-
-
- {item && (
- <>
-
-
- {t('dialog.save', 'Save')}
-
- >
- )}
- {!item && (
-
- >
- );
+ >}
+
+
+
+ {item && <>
+
+ {t('dialog.cancel', 'Cancel')}
+
+
+ {t('dialog.save', 'Save')}
+
+ >}
+ {!item && (
+
+ {t('dialog.close', 'Close')}
+
+ )}
+
+ >
}
diff --git a/databox/client/src/components/Dialog/Workspace/EditWorkspace.tsx b/databox/client/src/components/Dialog/Workspace/EditWorkspace.tsx
index 866833a57..6dbd0e783 100644
--- a/databox/client/src/components/Dialog/Workspace/EditWorkspace.tsx
+++ b/databox/client/src/components/Dialog/Workspace/EditWorkspace.tsx
@@ -3,9 +3,10 @@ import {putWorkspace} from '../../../api/collection';
import {useTranslation} from 'react-i18next';
import {toast} from 'react-toastify';
import {useFormSubmit} from '@alchemy/api';
-import {WorkspaceForm} from '../../Form/WorkspaceForm';
+import {WorkspaceForm, WorkspaceFormData} from '../../Form/WorkspaceForm';
import FormTab from '../Tabbed/FormTab';
import {DialogTabProps} from '../Tabbed/TabbedDialog';
+import {extendSortableList, flattenSortableList} from "../../Form/SortableCollectionWidget.tsx";
type Props = {
id: string;
@@ -16,8 +17,9 @@ export default function EditWorkspace({data, onClose, minHeight}: Props) {
const {t} = useTranslation();
const {submitting, submitted, handleSubmit, errors} = useFormSubmit({
- onSubmit: async (data: Workspace) => {
- return await putWorkspace(data.id, data);
+ defaultValues: normalizeFormData(data),
+ onSubmit: async (data: WorkspaceFormData) => {
+ return await putWorkspace(data.id, denormalizeFormData(data));
},
onSuccess: () => {
toast.success(
@@ -38,6 +40,7 @@ export default function EditWorkspace({data, onClose, minHeight}: Props) {
minHeight={minHeight}
>
);
}
+
+
+function denormalizeFormData(data: WorkspaceFormData): Workspace {
+ return {
+ ...data,
+ enabledLocales: flattenSortableList(data.enabledLocales),
+ localeFallbacks: flattenSortableList(data.localeFallbacks),
+ };
+}
+
+
+function normalizeFormData(data: Workspace): WorkspaceFormData {
+ return {
+ ...data,
+ enabledLocales: extendSortableList(data.enabledLocales),
+ localeFallbacks: extendSortableList(data.localeFallbacks),
+ };
+}
diff --git a/databox/client/src/components/Dialog/Workspace/RenditionDefinitionManager.tsx b/databox/client/src/components/Dialog/Workspace/RenditionDefinitionManager.tsx
index 0cb9c9d1a..211f45273 100644
--- a/databox/client/src/components/Dialog/Workspace/RenditionDefinitionManager.tsx
+++ b/databox/client/src/components/Dialog/Workspace/RenditionDefinitionManager.tsx
@@ -22,27 +22,20 @@ import {toast} from 'react-toastify';
import {useDirtyFormPrompt} from '../Tabbed/FormTab';
function Item({
- data,
- handleSubmit: onSubmit,
formId,
- submitting,
+ usedFormSubmit: {
+ register,
+ handleSubmit,
+ control,
+ formState: {errors},
+ submitting,
+ forbidNavigation,
+ },
workspaceId,
}: DefinitionItemFormProps) {
const {t} = useTranslation();
- const {
- register,
- handleSubmit,
- setError,
- control,
- formState: {errors, isDirty},
- } = useForm({
- defaultValues: {
- ...data,
- class: data?.class && (data?.class as RenditionClass)['@id'],
- },
- });
- useDirtyFormPrompt(isDirty);
+ useDirtyFormPrompt(forbidNavigation);
return (