New useNavigateApp (#9729)
Todo : - replace all instances of useNavigate( - remove getSettingsPagePath - add eslint rule to enfore usage of useNavigateApp instead of useNavigate
This commit is contained in:
+14
-8
@@ -2,7 +2,7 @@ import styled from '@emotion/styled';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { DateTime } from 'luxon';
|
||||
import { useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { Button, H2Title, IconRepeat, IconTrash, Section } from 'twenty-ui';
|
||||
|
||||
@@ -17,7 +17,6 @@ import { apiKeyTokenState } from '@/settings/developers/states/generatedApiKeyTo
|
||||
import { ApiKey } from '@/settings/developers/types/api-key/ApiKey';
|
||||
import { computeNewExpirationDate } from '@/settings/developers/utils/computeNewExpirationDate';
|
||||
import { formatExpiration } from '@/settings/developers/utils/formatExpiration';
|
||||
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
|
||||
import { SettingsPath } from '@/types/SettingsPath';
|
||||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
@@ -25,6 +24,8 @@ import { TextInput } from '@/ui/input/components/TextInput';
|
||||
import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal';
|
||||
import { SubMenuTopBarContainer } from '@/ui/layout/page/components/SubMenuTopBarContainer';
|
||||
import { useGenerateApiKeyTokenMutation } from '~/generated/graphql';
|
||||
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
|
||||
import { getSettingsPath } from '~/utils/navigation/getSettingsPath';
|
||||
|
||||
const StyledInfo = styled.span`
|
||||
color: ${({ theme }) => theme.font.color.light};
|
||||
@@ -47,7 +48,7 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
const [isDeleteApiKeyModalOpen, setIsDeleteApiKeyModalOpen] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const navigate = useNavigateSettings();
|
||||
const { apiKeyId = '' } = useParams();
|
||||
|
||||
const [apiKeyToken, setApiKeyToken] = useRecoilState(apiKeyTokenState);
|
||||
@@ -68,7 +69,6 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
setApiKeyName(record.name);
|
||||
},
|
||||
});
|
||||
const developerPath = getSettingsPagePath(SettingsPath.Developers);
|
||||
|
||||
const deleteIntegration = async (redirect = true) => {
|
||||
setIsLoading(true);
|
||||
@@ -79,7 +79,7 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
updateOneRecordInput: { revokedAt: DateTime.now().toString() },
|
||||
});
|
||||
if (redirect) {
|
||||
navigate(developerPath);
|
||||
navigate(SettingsPath.Developers);
|
||||
}
|
||||
} catch (err) {
|
||||
enqueueSnackBar(`Error deleting api key: ${err}`, {
|
||||
@@ -114,6 +114,7 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
token: tokenData.data?.generateApiKeyToken.token,
|
||||
};
|
||||
};
|
||||
|
||||
const regenerateApiKey = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
@@ -127,7 +128,9 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
|
||||
if (isNonEmptyString(apiKey?.token)) {
|
||||
setApiKeyToken(apiKey.token);
|
||||
navigate(`/settings/developers/api-keys/${apiKey.id}`);
|
||||
navigate(SettingsPath.DevelopersApiKeyDetail, {
|
||||
apiKeyId: apiKey.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -147,9 +150,12 @@ export const SettingsDevelopersApiKeyDetail = () => {
|
||||
links={[
|
||||
{
|
||||
children: 'Workspace',
|
||||
href: getSettingsPagePath(SettingsPath.Workspace),
|
||||
href: getSettingsPath(SettingsPath.Workspace),
|
||||
},
|
||||
{
|
||||
children: 'Developers',
|
||||
href: getSettingsPath(SettingsPath.Developers),
|
||||
},
|
||||
{ children: 'Developers', href: developerPath },
|
||||
{ children: `${apiKeyName} API Key` },
|
||||
]}
|
||||
>
|
||||
|
||||
+9
-7
@@ -1,6 +1,5 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { H2Title, Section } from 'twenty-ui';
|
||||
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
@@ -10,7 +9,6 @@ import { SettingsPageContainer } from '@/settings/components/SettingsPageContain
|
||||
import { EXPIRATION_DATES } from '@/settings/developers/constants/ExpirationDates';
|
||||
import { apiKeyTokenState } from '@/settings/developers/states/generatedApiKeyTokenState';
|
||||
import { ApiKey } from '@/settings/developers/types/api-key/ApiKey';
|
||||
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
|
||||
import { SettingsPath } from '@/types/SettingsPath';
|
||||
import { Select } from '@/ui/input/components/Select';
|
||||
import { TextInput } from '@/ui/input/components/TextInput';
|
||||
@@ -18,11 +16,13 @@ import { SubMenuTopBarContainer } from '@/ui/layout/page/components/SubMenuTopBa
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { Key } from 'ts-key-enum';
|
||||
import { useGenerateApiKeyTokenMutation } from '~/generated/graphql';
|
||||
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { getSettingsPath } from '~/utils/navigation/getSettingsPath';
|
||||
|
||||
export const SettingsDevelopersApiKeysNew = () => {
|
||||
const [generateOneApiKeyToken] = useGenerateApiKeyTokenMutation();
|
||||
const navigate = useNavigate();
|
||||
const navigateSettings = useNavigateSettings();
|
||||
const setApiKeyToken = useSetRecoilState(apiKeyTokenState);
|
||||
const [formValues, setFormValues] = useState<{
|
||||
name: string;
|
||||
@@ -58,7 +58,9 @@ export const SettingsDevelopersApiKeysNew = () => {
|
||||
});
|
||||
if (isDefined(tokenData.data?.generateApiKeyToken)) {
|
||||
setApiKeyToken(tokenData.data.generateApiKeyToken.token);
|
||||
navigate(`/settings/developers/api-keys/${newApiKey.id}`);
|
||||
navigateSettings(SettingsPath.DevelopersApiKeyDetail, {
|
||||
apiKeyId: newApiKey.id,
|
||||
});
|
||||
}
|
||||
};
|
||||
const canSave = !!formValues.name && createOneApiKey;
|
||||
@@ -68,11 +70,11 @@ export const SettingsDevelopersApiKeysNew = () => {
|
||||
links={[
|
||||
{
|
||||
children: 'Workspace',
|
||||
href: getSettingsPagePath(SettingsPath.Workspace),
|
||||
href: getSettingsPath(SettingsPath.Workspace),
|
||||
},
|
||||
{
|
||||
children: 'Developers',
|
||||
href: getSettingsPagePath(SettingsPath.Developers),
|
||||
href: getSettingsPath(SettingsPath.Developers),
|
||||
},
|
||||
{ children: 'New Key' },
|
||||
]}
|
||||
@@ -80,7 +82,7 @@ export const SettingsDevelopersApiKeysNew = () => {
|
||||
<SaveAndCancelButtons
|
||||
isSaveDisabled={!canSave}
|
||||
onCancel={() => {
|
||||
navigate('/settings/developers');
|
||||
navigateSettings(SettingsPath.Developers);
|
||||
}}
|
||||
onSave={handleSave}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user