Skip to content

The open alternative to Salesforce, designed for AI.

3.4 KB
Raw Blame
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { domainConfigurationState } from '@/domain-manager/states/domainConfigurationState';
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import {
  SUBDOMAIN_CHANGE_CONFIRMATION_MODAL_ID,
  useSettingsSubdomain,
} from '@/settings/domains/hooks/useSettingsSubdomain';
import { TextInput } from '@/ui/input/components/TextInput';
import { ConfirmationDialog } from '@/ui/layout/dialog/components/ConfirmationDialog';
import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { Trans, useLingui } from '@lingui/react/macro';
import { styled } from '@linaria/react';
import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath, isDefined } from 'twenty-shared/utils';
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
import { Section } from 'twenty-ui/components/layout';

const StyledDomainFormWrapper = styled.div`
  align-items: center;
  display: flex;
`;

export const SettingsSubdomain = () => {
  const navigate = useNavigateSettings();
  const { t } = useLingui();
  const domainConfiguration = useAtomStateValue(domainConfigurationState);
  const currentWorkspace = useAtomStateValue(currentWorkspaceState);

  const {
    subdomain,
    error,
    isSubmitting,
    isSaveDisabled,
    handleChange,
    handleSave,
    handleConfirm,
  } = useSettingsSubdomain();

  return (
    <>
      <SettingsPageLayout
        title={t`Subdomain`}
        links={[
          {
            children: <Trans>Workspace</Trans>,
            href: getSettingsPath(SettingsPath.General),
          },
          {
            children: <Trans>General</Trans>,
            href: getSettingsPath(SettingsPath.General),
          },
          { children: <Trans>Subdomain</Trans> },
        ]}
        actionButton={
          <SaveAndCancelButtons
            onCancel={() => navigate(SettingsPath.General)}
            isSaveDisabled={isSaveDisabled}
            isLoading={isSubmitting}
            onSave={handleSave}
          />
        }
      >
        <SettingsPageContainer>
          <Section.Root>
            <Section.Header
              title={t`Subdomain`}
              description={t`Set the name of your subdomain`}
            />
            <StyledDomainFormWrapper>
              <TextInput
                value={subdomain}
                type="text"
                onChange={handleChange}
                error={error}
                disabled={!!currentWorkspace?.customDomain}
                rightAdornment={
                  isDefined(domainConfiguration.frontDomain)
                    ? `.${domainConfiguration.frontDomain}`
                    : undefined
                }
                fullWidth
              />
            </StyledDomainFormWrapper>
          </Section.Root>
        </SettingsPageContainer>
      </SettingsPageLayout>
      <ConfirmationDialog
        dialogId={SUBDOMAIN_CHANGE_CONFIRMATION_MODAL_ID}
        title={t`Change subdomain?`}
        subtitle={t`You're about to change your workspace subdomain. This action will log out all users.`}
        onConfirmClick={handleConfirm}
      />
    </>
  );
};