Skip to content

Commit

Permalink
feat: Implement navigate(-1) instead
Browse files Browse the repository at this point in the history
  • Loading branch information
aikuci committed Jul 23, 2024
1 parent f3d6ea3 commit d69d345
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export const useGetAvailableFieldsForKanban = () => {
navigate(
`/settings/objects/${getObjectSlug(
objectMetadataItem,
)}/new-field/step-2?fieldType=${FieldMetadataType.Select}`,
)}/new-field/step-2?fieldType=${
FieldMetadataType.Select
}&navigateBack=true`,
);
} else {
navigate(`/settings/objects`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import styled from '@emotion/styled';
import { useEffect } from 'react';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';
import { useNavigate, useParams } from 'react-router-dom';
import { H2Title, IconPlus, IconSettings } from 'twenty-ui';

import { LABEL_IDENTIFIER_FIELD_METADATA_TYPES } from '@/object-metadata/constants/LabelIdentifierFieldMetadataTypes';
Expand Down Expand Up @@ -33,7 +32,6 @@ import { TableHeader } from '@/ui/layout/table/components/TableHeader';
import { TableSection } from '@/ui/layout/table/components/TableSection';
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import { UndecoratedLink } from '@/ui/navigation/link/components/UndecoratedLink';
import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState';

const StyledDiv = styled.div`
display: flex;
Expand All @@ -43,11 +41,6 @@ const StyledDiv = styled.div`

export const SettingsObjectDetail = () => {
const navigate = useNavigate();
const location = useLocation();
const setNavigationMemorizedUrl = useSetRecoilState(
navigationMemorizedUrlState,
);
setNavigationMemorizedUrl(location.pathname);

const { objectSlug = '' } = useParams();
const { findActiveObjectMetadataItemBySlug } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import pick from 'lodash.pick';
import { useEffect, useState } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { H2Title, IconSettings } from 'twenty-ui';
import { z } from 'zod';

Expand All @@ -30,7 +29,6 @@ import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer';
import { Section } from '@/ui/layout/section/components/Section';
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState';
import { View } from '@/views/types/View';
import { ViewType } from '@/views/types/ViewType';
import { FieldMetadataType } from '~/generated-metadata/graphql';
Expand All @@ -48,11 +46,11 @@ const StyledSettingsObjectFieldTypeSelect = styled(
`;

export const SettingsObjectNewFieldStep2 = () => {
const navigationMemorizedUrl = useRecoilValue(navigationMemorizedUrlState);
const navigate = useNavigate();
const { objectSlug = '' } = useParams();
const [searchParams] = useSearchParams();
const fieldType = searchParams.get('fieldType');
const navigateBack = searchParams.get('navigateBack');
const { enqueueSnackBar } = useSnackBar();

const { findActiveObjectMetadataItemBySlug } =
Expand Down Expand Up @@ -150,7 +148,11 @@ export const SettingsObjectNewFieldStep2 = () => {
});
}

navigate(navigationMemorizedUrl, { replace: true });
if (navigateBack?.toLowerCase() === 'true') {
navigate(-1);
} else {
navigate(`/settings/objects/${objectSlug}`);
}

// TODO: fix optimistic update logic
// Forcing a refetch for now but it's not ideal
Expand Down Expand Up @@ -198,7 +200,10 @@ export const SettingsObjectNewFieldStep2 = () => {
<SaveAndCancelButtons
isSaveDisabled={!canSave}
isCancelDisabled={isSubmitting}
onCancel={() => navigate(navigationMemorizedUrl, { replace: true })}
onCancel={() => {
if (navigateBack?.toLowerCase() === 'true') navigate(-1);
else navigate(`/settings/objects/${objectSlug}`);
}}
onSave={formConfig.handleSubmit(handleSave)}
/>
)}
Expand Down

0 comments on commit d69d345

Please sign in to comment.