8034c7725f
Reorganizes `twenty-ui`'s component organization to follow how the best
UI libraries (MUI, Mantine, Base UI, Polaris) structure their source,
now that the package has stabilized.
**Taxonomy** — dissolves the meaningless `components/` junk-drawer and
the 107-file `display/` mega-category. New domains/subpaths:
`data-display`, `typography`, `icon`, `surfaces`; `feedback` and
`layout` absorb the rest (banners/callout/info + placeholders →
feedback; modal/card → surfaces; motion + separators → layout).
**Per-component layout** — every component is now
`<domain>/<ComponentName>/<ComponentName>.tsx` with colocated
styles/stories/types, `internal/` for private helpers and `parts/` for
re-exported compound sub-parts. The redundant inner `/components/` is
gone. `icon` and `json-visualizer` are kept as cohesive subsystems.
**Also:** adds a tree-shakeable root barrel (`import { Button } from
'twenty-ui'`), the generator now owns `individual-entry.ts`, and a real
barrel-leak bug is fixed (private `internals/` parts were leaking into
the public API).
Consumer imports (~1.2k files) and the `twenty-sdk` UI aggregator were
updated by codemod. The change is **export-neutral** except 16
intentionally-removed private internals symbols (all verified
unconsumed). Gates green: typecheck, lint, build, size-limit, storybook.
<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/21745?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
121 lines
4.6 KiB
TypeScript
121 lines
4.6 KiB
TypeScript
import { useCreateOneObjectMetadataItem } from '@/object-metadata/hooks/useCreateOneObjectMetadataItem';
|
|
import { objectMetadataItemsSelector } from '@/object-metadata/states/objectMetadataItemsSelector';
|
|
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
|
|
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
|
|
import { SETTINGS_OBJECT_MODEL_IS_LABEL_SYNCED_WITH_NAME_LABEL_DEFAULT_VALUE } from '@/settings/constants/SettingsObjectModel';
|
|
import { SettingsDataModelObjectAboutForm } from '@/settings/data-model/objects/forms/components/SettingsDataModelObjectAboutForm';
|
|
import { getConflictingObjectMetadataItem } from '@/settings/data-model/utils/getConflictingObjectMetadataItem';
|
|
import {
|
|
type SettingsDataModelObjectAboutFormValues,
|
|
settingsDataModelObjectAboutFormSchema,
|
|
} from '@/settings/data-model/validation-schemas/settingsDataModelObjectAboutFormSchema';
|
|
import { isDDLLockedState } from '@/client-config/states/isDDLLockedState';
|
|
import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
|
|
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import { useLingui } from '@lingui/react/macro';
|
|
import { useState } from 'react';
|
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
import { SettingsPath } from 'twenty-shared/types';
|
|
import { getSettingsPath, isDefined } from 'twenty-shared/utils';
|
|
import { H2Title } from 'twenty-ui/typography';
|
|
import { Section } from 'twenty-ui/layout';
|
|
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
|
|
|
|
export const SettingsNewObject = () => {
|
|
const { t } = useLingui();
|
|
const navigate = useNavigateSettings();
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const { createOneObjectMetadataItem } = useCreateOneObjectMetadataItem();
|
|
const isDDLLocked = useAtomStateValue(isDDLLockedState);
|
|
const objectMetadataItems = useAtomStateValue(objectMetadataItemsSelector);
|
|
|
|
const formConfig = useForm<SettingsDataModelObjectAboutFormValues>({
|
|
mode: 'onChange',
|
|
resolver: zodResolver(settingsDataModelObjectAboutFormSchema),
|
|
defaultValues: {
|
|
color: 'gray',
|
|
isLabelSyncedWithName:
|
|
SETTINGS_OBJECT_MODEL_IS_LABEL_SYNCED_WITH_NAME_LABEL_DEFAULT_VALUE,
|
|
},
|
|
});
|
|
|
|
const nameSingular = formConfig.watch('nameSingular');
|
|
const namePlural = formConfig.watch('namePlural');
|
|
|
|
const conflictingObjectMetadataItem = getConflictingObjectMetadataItem({
|
|
objectMetadataItems,
|
|
nameSingular,
|
|
namePlural,
|
|
});
|
|
|
|
const hasNameConflict = isDefined(conflictingObjectMetadataItem);
|
|
|
|
const { isValid, isSubmitting } = formConfig.formState;
|
|
const canSave = isValid && !isSubmitting && !hasNameConflict && !isDDLLocked;
|
|
|
|
const handleSave = async (
|
|
formValues: SettingsDataModelObjectAboutFormValues,
|
|
) => {
|
|
setIsLoading(true);
|
|
|
|
const result = await createOneObjectMetadataItem(formValues);
|
|
|
|
if (result.status === 'successful') {
|
|
const response = result.response.data;
|
|
navigate(
|
|
response ? SettingsPath.ObjectDetail : SettingsPath.Objects,
|
|
response
|
|
? { objectNamePlural: response.createOneObject.namePlural }
|
|
: undefined,
|
|
);
|
|
}
|
|
|
|
setIsLoading(false);
|
|
};
|
|
|
|
return (
|
|
// oxlint-disable-next-line react/jsx-props-no-spreading
|
|
<FormProvider {...formConfig}>
|
|
<SettingsPageLayout
|
|
title={t`New Object`}
|
|
links={[
|
|
{
|
|
children: t`Workspace`,
|
|
href: getSettingsPath(SettingsPath.General),
|
|
},
|
|
{
|
|
children: t`Objects`,
|
|
href: getSettingsPath(SettingsPath.Objects),
|
|
},
|
|
{ children: t`New` },
|
|
]}
|
|
actionButton={
|
|
<SaveAndCancelButtons
|
|
isSaveDisabled={!canSave}
|
|
isLoading={isLoading}
|
|
isCancelDisabled={isSubmitting}
|
|
onCancel={() => navigate(SettingsPath.Objects)}
|
|
onSave={formConfig.handleSubmit(handleSave)}
|
|
/>
|
|
}
|
|
>
|
|
<SettingsPageContainer>
|
|
<Section>
|
|
<H2Title
|
|
title={t`About`}
|
|
description={t`Define the name and description of your object`}
|
|
/>
|
|
<SettingsDataModelObjectAboutForm
|
|
onNewDirtyField={() => formConfig.trigger()}
|
|
conflictingObjectMetadataItem={
|
|
!isLoading ? conflictingObjectMetadataItem : undefined
|
|
}
|
|
/>
|
|
</Section>
|
|
</SettingsPageContainer>
|
|
</SettingsPageLayout>
|
|
</FormProvider>
|
|
);
|
|
};
|