Skip to content

The open alternative to Salesforce, designed for AI.

2062 view edit an api key (#2231)

martmullfc4075b37221
diff --git a/front/nyc.config.js b/front/nyc.config.js
index 43799fe88ad..28b9d3da963 100644
--- a/front/nyc.config.js
+++ b/front/nyc.config.js
@@ -17,9 +17,9 @@ const modulesCoverage = {
};
const pagesCoverage = {
- "statements": 60,
- "lines": 60,
- "functions": 55,
+ "statements": 50,
+ "lines": 50,
+ "functions": 45,
"exclude": [
"src/generated/**/*",
"src/modules/**/*",
@@ -32,4 +32,4 @@ const storybookStoriesFolders = process.env.STORYBOOK_SCOPE;
module.exports = storybookStoriesFolders === 'pages' ?
pagesCoverage : storybookStoriesFolders === 'modules' ? modulesCoverage
- : globalCoverage;
\ No newline at end of file
+ : globalCoverage;
diff --git a/front/src/generated/graphql.tsx b/front/src/generated/graphql.tsx
index 54859b2f4d8..add5635d7ca 100644
--- a/front/src/generated/graphql.tsx
+++ b/front/src/generated/graphql.tsx
@@ -3807,22 +3807,7 @@ export type GetActivitiesQueryVariables = Exact<{
}>;
-export type GetActivitiesQuery = {
- __typename?: 'Query',
- findManyActivities: Array<{
- __typename?: 'Activity';
- id: string;
- createdAt: string,
- title?: string | null,
- body?: string | null,
- type: ActivityType,
- completedAt?: string | null,
- dueAt?: string | null,
- assignee?: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string, avatarUrl?: string | null } | null,
- author: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string },
- comments?: Array<Comment>,
- activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, companyId?: string | null, personId?: string | null, company?: { __typename?: 'Company', id: string, name: string, domainName: string } | null, person?: { __typename?: 'Person', id: string, displayName: string, avatarUrl?: string | null } | null }> | null
-}> };
+export type GetActivitiesQuery = { __typename?: 'Query', findManyActivities: Array<{ __typename?: 'Activity', id: string, createdAt: string, title?: string | null, body?: string | null, type: ActivityType, completedAt?: string | null, dueAt?: string | null, assignee?: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string, avatarUrl?: string | null } | null, author: { __typename?: 'User', id: string, firstName?: string | null, lastName?: string | null, displayName: string }, comments?: Array<{ __typename?: 'Comment', id: string, body: string, createdAt: string, updatedAt: string, author: { __typename?: 'User', id: string, displayName: string, firstName?: string | null, lastName?: string | null, avatarUrl?: string | null } }> | null, activityTargets?: Array<{ __typename?: 'ActivityTarget', id: string, companyId?: string | null, personId?: string | null, company?: { __typename?: 'Company', id: string, name: string, domainName: string } | null, person?: { __typename?: 'Person', id: string, displayName: string, avatarUrl?: string | null } | null }> | null }> };
export type GetActivitiesByTargetsQueryVariables = Exact<{
activityTargetIds: Array<Scalars['String']> | Scalars['String'];
@@ -4225,7 +4210,12 @@ export type GetApiKeyQueryVariables = Exact<{
}>;
-export type GetApiKeyQuery = { __typename?: 'Query', findManyApiKey: Array<{ __typename?: 'ApiKey', id: string, name: string, expiresAt?: string | null }> };
+export type GetApiKeyQuery = { __typename?: 'Query', findManyApiKey: Array<{ __typename?: 'ApiKey', id: string, name: string, expiresAt?: string | null, createdAt: string }> };
+
+export type GetApiKeysQueryVariables = Exact<{ [key: string]: never; }>;
+
+
+export type GetApiKeysQuery = { __typename?: 'Query', findManyApiKey: Array<{ __typename?: 'ApiKey', id: string, name: string, expiresAt?: string | null, createdAt: string }> };
export type UserFieldsFragmentFragment = { __typename?: 'User', id: string, email: string, displayName: string, firstName?: string | null, lastName?: string | null };
@@ -6954,6 +6944,7 @@ export const GetApiKeyDocument = gql`
id
name
expiresAt
+ createdAt
}
}
`;
@@ -6985,6 +6976,43 @@ export function useGetApiKeyLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<
export type GetApiKeyQueryHookResult = ReturnType<typeof useGetApiKeyQuery>;
export type GetApiKeyLazyQueryHookResult = ReturnType<typeof useGetApiKeyLazyQuery>;
export type GetApiKeyQueryResult = Apollo.QueryResult<GetApiKeyQuery, GetApiKeyQueryVariables>;
+export const GetApiKeysDocument = gql`
+ query GetApiKeys {
+ findManyApiKey {
+ id
+ name
+ expiresAt
+ createdAt
+ }
+}
+ `;
+
+/**
+ * __useGetApiKeysQuery__
+ *
+ * To run a query within a React component, call `useGetApiKeysQuery` and pass it any options that fit your needs.
+ * When your component renders, `useGetApiKeysQuery` returns an object from Apollo Client that contains loading, error, and data properties
+ * you can use to render your UI.
+ *
+ * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
+ *
+ * @example
+ * const { data, loading, error } = useGetApiKeysQuery({
+ * variables: {
+ * },
+ * });
+ */
+export function useGetApiKeysQuery(baseOptions?: Apollo.QueryHookOptions<GetApiKeysQuery, GetApiKeysQueryVariables>) {
+ const options = {...defaultOptions, ...baseOptions}
+ return Apollo.useQuery<GetApiKeysQuery, GetApiKeysQueryVariables>(GetApiKeysDocument, options);
+ }
+export function useGetApiKeysLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetApiKeysQuery, GetApiKeysQueryVariables>) {
+ const options = {...defaultOptions, ...baseOptions}
+ return Apollo.useLazyQuery<GetApiKeysQuery, GetApiKeysQueryVariables>(GetApiKeysDocument, options);
+ }
+export type GetApiKeysQueryHookResult = ReturnType<typeof useGetApiKeysQuery>;
+export type GetApiKeysLazyQueryHookResult = ReturnType<typeof useGetApiKeysLazyQuery>;
+export type GetApiKeysQueryResult = Apollo.QueryResult<GetApiKeysQuery, GetApiKeysQueryVariables>;
export const DeleteUserAccountDocument = gql`
mutation DeleteUserAccount {
deleteUserAccount {
diff --git a/front/src/modules/activities/notes/components/NoteCard.tsx b/front/src/modules/activities/notes/components/NoteCard.tsx
index b93e41aeac6..9089713c209 100644
--- a/front/src/modules/activities/notes/components/NoteCard.tsx
+++ b/front/src/modules/activities/notes/components/NoteCard.tsx
@@ -9,7 +9,7 @@ import {
GenericFieldContextType,
} from '@/ui/data/field/contexts/FieldContext';
import { IconComment } from '@/ui/display/icon';
-import { Activity, ActivityTarget } from '~/generated/graphql';
+import { Activity, ActivityTarget, Comment } from '~/generated/graphql';
const StyledCard = styled.div`
align-items: flex-start;
@@ -76,9 +76,10 @@ export const NoteCard = ({
}: {
note: Pick<
Activity,
- 'id' | 'title' | 'body' | 'type' | 'completedAt' | 'dueAt' | 'comments'
+ 'id' | 'title' | 'body' | 'type' | 'completedAt' | 'dueAt'
> & {
activityTargets?: Array<Pick<ActivityTarget, 'id'>> | null;
+ comments?: Array<Pick<Comment, 'id'>> | null;
};
}) => {
const theme = useTheme();
diff --git a/front/src/modules/settings/developers/components/ApiKeyInput.tsx b/front/src/modules/settings/developers/components/ApiKeyInput.tsx
index 36639f35fcf..e727c055bdf 100644
--- a/front/src/modules/settings/developers/components/ApiKeyInput.tsx
+++ b/front/src/modules/settings/developers/components/ApiKeyInput.tsx
@@ -5,7 +5,6 @@ import { IconCopy } from '@/ui/display/icon';
import { useSnackBar } from '@/ui/feedback/snack-bar/hooks/useSnackBar';
import { Button } from '@/ui/input/button/components/Button';
import { TextInput } from '@/ui/input/components/TextInput';
-import { beautifyDateDiff } from '~/utils/date-utils';
const StyledContainer = styled.div`
display: flex;
@@ -17,22 +16,16 @@ const StyledLinkContainer = styled.div`
margin-right: ${({ theme }) => theme.spacing(2)};
`;
-type ApiKeyInputProps = { expiresAt?: string | null; apiKey: string };
+type ApiKeyInputProps = { apiKey: string };
-export const ApiKeyInput = ({ expiresAt, apiKey }: ApiKeyInputProps) => {
+export const ApiKeyInput = ({ apiKey }: ApiKeyInputProps) => {
const theme = useTheme();
- const computeInfo = () => {
- if (!expiresAt) {
- return '';
- }
- return `This key will expire in ${beautifyDateDiff(expiresAt)}`;
- };
const { enqueueSnackBar } = useSnackBar();
return (
<StyledContainer>
<StyledLinkContainer>
- <TextInput info={computeInfo()} value={apiKey} fullWidth />
+ <TextInput value={apiKey} fullWidth />
</StyledLinkContainer>
<Button
Icon={IconCopy}
diff --git a/front/src/modules/settings/developers/components/SettingsApiKeysFieldItemTableRow.tsx b/front/src/modules/settings/developers/components/SettingsApiKeysFieldItemTableRow.tsx
index aab2c4fafca..ab658d50ee5 100644
--- a/front/src/modules/settings/developers/components/SettingsApiKeysFieldItemTableRow.tsx
+++ b/front/src/modules/settings/developers/components/SettingsApiKeysFieldItemTableRow.tsx
@@ -1,12 +1,11 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
+import { ApiFieldItem } from '@/settings/developers/types/ApiFieldItem';
import { IconChevronRight } from '@/ui/display/icon';
import { TableCell } from '@/ui/layout/table/components/TableCell';
import { TableRow } from '@/ui/layout/table/components/TableRow';
-import { ApisFiedlItem } from '../types/ApisFieldItem';
-
export const StyledApisFieldTableRow = styled(TableRow)`
grid-template-columns: 180px 148px 148px 36px;
`;
@@ -27,13 +26,15 @@ const StyledIconChevronRight = styled(IconChevronRight)`
export const SettingsApiKeysFieldItemTableRow = ({
fieldItem,
+ onClick,
}: {
- fieldItem: ApisFiedlItem;
+ fieldItem: ApiFieldItem;
+ onClick: () => void;
}) => {
const theme = useTheme();
return (
- <StyledApisFieldTableRow onClick={() => {}}>
+ <StyledApisFieldTableRow onClick={() => onClick()}>
<StyledNameTableCell>{fieldItem.name}</StyledNameTableCell>
<TableCell color={theme.font.color.tertiary}>Internal</TableCell>{' '}
<TableCell
diff --git a/front/src/modules/settings/developers/components/__stories__/ApiKeyInput.stories.tsx b/front/src/modules/settings/developers/components/__stories__/ApiKeyInput.stories.tsx
index c0375de22a6..f150e32a85b 100644
--- a/front/src/modules/settings/developers/components/__stories__/ApiKeyInput.stories.tsx
+++ b/front/src/modules/settings/developers/components/__stories__/ApiKeyInput.stories.tsx
@@ -8,7 +8,6 @@ const meta: Meta<typeof ApiKeyInput> = {
component: ApiKeyInput,
decorators: [ComponentDecorator],
args: {
- expiresAt: '2123-11-06T23:59:59.825Z',
apiKey:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0d2VudHktN2VkOWQyMTItMWMyNS00ZDAyLWJmMjUtNmFlY2NmN2VhNDE5IiwiaWF0IjoxNjk4MTQyODgyLCJleHAiOjE2OTk0MDE1OTksImp0aSI6ImMyMmFiNjQxLTVhOGYtNGQwMC1iMDkzLTk3MzUwYTM2YzZkOSJ9.JIe2TX5IXrdNl3n-kRFp3jyfNUE7unzXZLAzm2Gxl98',
},
diff --git a/front/src/modules/settings/developers/constants/expirationDates.ts b/front/src/modules/settings/developers/constants/expirationDates.ts
index 746661e7a01..028ac9ddef4 100644
--- a/front/src/modules/settings/developers/constants/expirationDates.ts
+++ b/front/src/modules/settings/developers/constants/expirationDates.ts
@@ -1,5 +1,5 @@
export const ExpirationDates: {
- value: number;
+ value: number | null;
label: string;
}[] = [
{ label: '15 days', value: 15 },
@@ -7,5 +7,5 @@ export const ExpirationDates: {
{ label: '90 days', value: 90 },
{ label: '1 year', value: 365 },
{ label: '2 years', value: 2 * 365 },
- { label: 'Never', value: 10 * 365 },
+ { label: 'Never', value: null },
];
diff --git a/front/src/modules/settings/developers/constants/mockObjects.ts b/front/src/modules/settings/developers/constants/mockObjects.ts
deleted file mode 100644
index a37b0e3463f..00000000000
--- a/front/src/modules/settings/developers/constants/mockObjects.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import { v4 } from 'uuid';
-
-import { ApisFiedlItem } from '../types/ApisFieldItem';
-
-export const activeApiKeyItems: ApisFiedlItem[] = [
- {
- id: v4(),
- name: 'Zapier key',
- type: 'internal',
- expiration: 'In 80 days',
- },
- {
- id: v4(),
- name: 'Notion',
- type: 'internal',
- expiration: 'Expired',
- },
- {
- id: v4(),
- name: 'Trello',
- type: 'internal',
- expiration: 'In 1 year',
- },
- {
- id: v4(),
- name: 'Cargo',
- type: 'published',
- expiration: 'Never',
- },
- {
- id: v4(),
- name: 'Backoffice',
- type: 'published',
- expiration: 'In 32 days',
- },
-];
diff --git a/front/src/modules/settings/developers/graphql/queries/getApiKey.ts b/front/src/modules/settings/developers/graphql/queries/getApiKey.ts
index 2c91682cf2a..d2d0629cc58 100644
--- a/front/src/modules/settings/developers/graphql/queries/getApiKey.ts
+++ b/front/src/modules/settings/developers/graphql/queries/getApiKey.ts
@@ -6,6 +6,7 @@ export const GET_API_KEY = gql`
id
name
expiresAt
+ createdAt
}
}
`;
diff --git a/front/src/modules/settings/developers/graphql/queries/getApiKeys.ts b/front/src/modules/settings/developers/graphql/queries/getApiKeys.ts
new file mode 100644
index 00000000000..e5dfe37ef75
--- /dev/null
+++ b/front/src/modules/settings/developers/graphql/queries/getApiKeys.ts
@@ -0,0 +1,12 @@
+import { gql } from '@apollo/client';
+
+export const GET_API_KEYS = gql`
+ query GetApiKeys {
+ findManyApiKey {
+ id
+ name
+ expiresAt
+ createdAt
+ }
+ }
+`;
diff --git a/front/src/modules/settings/developers/hooks/useGeneratedApiKeys.ts b/front/src/modules/settings/developers/hooks/useGeneratedApiKeys.ts
new file mode 100644
index 00000000000..888337370a9
--- /dev/null
+++ b/front/src/modules/settings/developers/hooks/useGeneratedApiKeys.ts
@@ -0,0 +1,12 @@
+import { useRecoilCallback } from 'recoil';
+
+import { generatedApiKeyFamilyState } from '@/settings/developers/states/generatedApiKeyFamilyState';
+
+export const useGeneratedApiKeys = () => {
+ return useRecoilCallback(
+ ({ set }) =>
+ (apiKeyId: string, apiKey: string | null) => {
+ set(generatedApiKeyFamilyState(apiKeyId), apiKey);
+ },
+ );
+};
diff --git a/front/src/modules/settings/developers/states/generatedApiKeyFamilyState.ts b/front/src/modules/settings/developers/states/generatedApiKeyFamilyState.ts
new file mode 100644
index 00000000000..329e1b6487b
--- /dev/null
+++ b/front/src/modules/settings/developers/states/generatedApiKeyFamilyState.ts
@@ -0,0 +1,9 @@
+import { atomFamily } from 'recoil';
+
+export const generatedApiKeyFamilyState = atomFamily<
+ string | null | undefined,
+ string
+>({
+ key: 'generatedApiKeyFamilyState',
+ default: null,
+});
diff --git a/front/src/modules/settings/developers/states/generatedApiKeyState.ts b/front/src/modules/settings/developers/states/generatedApiKeyState.ts
deleted file mode 100644
index 73701d1e2e1..00000000000
--- a/front/src/modules/settings/developers/states/generatedApiKeyState.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import { atom } from 'recoil';
-
-export const generatedApiKeyState = atom<string | null | undefined>({
- key: 'generatedApiKeyState',
- default: null,
-});
diff --git a/front/src/modules/settings/developers/types/ApisFieldItem.ts b/front/src/modules/settings/developers/types/ApiFieldItem.ts
similarity index 74%
rename from front/src/modules/settings/developers/types/ApisFieldItem.ts
rename to front/src/modules/settings/developers/types/ApiFieldItem.ts
index 1dfa8826ac2..278b344884d 100644
--- a/front/src/modules/settings/developers/types/ApisFieldItem.ts
+++ b/front/src/modules/settings/developers/types/ApiFieldItem.ts
@@ -1,4 +1,4 @@
-export type ApisFiedlItem = {
+export type ApiFieldItem = {
id: string;
name: string;
type: 'internal' | 'published';
diff --git a/front/src/modules/settings/developers/utils/__tests__/compute-new-expiration-date.test.ts b/front/src/modules/settings/developers/utils/__tests__/compute-new-expiration-date.test.ts
new file mode 100644
index 00000000000..bd2a1db5bf7
--- /dev/null
+++ b/front/src/modules/settings/developers/utils/__tests__/compute-new-expiration-date.test.ts
@@ -0,0 +1,23 @@
+import { computeNewExpirationDate } from '@/settings/developers/utils/compute-new-expiration-date';
+
+jest.useFakeTimers().setSystemTime(new Date('2024-01-01T00:00:00.000Z'));
+
+describe('computeNewExpirationDate', () => {
+ it('should compute properly', () => {
+ const expiresAt = '2023-01-10T00:00:00.000Z';
+ const createdAt = '2023-01-01T00:00:00.000Z';
+ const result = computeNewExpirationDate(expiresAt, createdAt);
+ expect(result).toEqual('2024-01-10T00:00:00.000Z');
+ });
+ it('should compute properly with same values', () => {
+ const expiresAt = '2023-01-01T10:00:00.000Z';
+ const createdAt = '2023-01-01T10:00:00.000Z';
+ const result = computeNewExpirationDate(expiresAt, createdAt);
+ expect(result).toEqual('2024-01-01T00:00:00.000Z');
+ });
+ it('should compute properly with no expiration', () => {
+ const createdAt = '2023-01-01T10:00:00.000Z';
+ const result = computeNewExpirationDate(undefined, createdAt);
+ expect(result).toEqual(null);
+ });
+});
diff --git a/front/src/modules/settings/developers/utils/__tests__/format-expiration.test.ts b/front/src/modules/settings/developers/utils/__tests__/format-expiration.test.ts
new file mode 100644
index 00000000000..8a406e9bbd7
--- /dev/null
+++ b/front/src/modules/settings/developers/utils/__tests__/format-expiration.test.ts
@@ -0,0 +1,34 @@
+import { formatExpiration } from '@/settings/developers/utils/format-expiration';
+
+jest.useFakeTimers().setSystemTime(new Date('2024-01-01T00:00:00.000Z'));
+
+describe('formatExpiration', () => {
+ it('should format properly when expiresAt is null', () => {
+ const expiresAt = null;
+ const result = formatExpiration(expiresAt);
+ expect(result).toEqual('Never');
+ const resultWithExpiresMention = formatExpiration(expiresAt, true);
+ expect(resultWithExpiresMention).toEqual('Never expires');
+ });
+ it('should format properly when expiresAt is not null', () => {
+ const expiresAt = '2024-01-10T00:00:00.000Z';
+ const result = formatExpiration(expiresAt);
+ expect(result).toEqual('In 9 days');
+ const resultWithExpiresMention = formatExpiration(expiresAt, true);
+ expect(resultWithExpiresMention).toEqual('Expires in 9 days');
+ });
+ it('should format properly when expiresAt is large', () => {
+ const expiresAt = '2034-01-10T00:00:00.000Z';
+ const result = formatExpiration(expiresAt);
+ expect(result).toEqual('In 10 years');
+ const resultWithExpiresMention = formatExpiration(expiresAt, true);
+ expect(resultWithExpiresMention).toEqual('Expires in 10 years');
+ });
+ it('should format properly when expiresAt is large and long version', () => {
+ const expiresAt = '2034-01-10T00:00:00.000Z';
+ const result = formatExpiration(expiresAt, undefined, false);
+ expect(result).toEqual('In 10 years and 9 days');
+ const resultWithExpiresMention = formatExpiration(expiresAt, true, false);
+ expect(resultWithExpiresMention).toEqual('Expires in 10 years and 9 days');
+ });
+});
diff --git a/front/src/modules/settings/developers/utils/compute-new-expiration-date.ts b/front/src/modules/settings/developers/utils/compute-new-expiration-date.ts
new file mode 100644
index 00000000000..4dc342969b9
--- /dev/null
+++ b/front/src/modules/settings/developers/utils/compute-new-expiration-date.ts
@@ -0,0 +1,14 @@
+import { DateTime } from 'luxon';
+
+export const computeNewExpirationDate = (
+ expiresAt: string | null | undefined,
+ createdAt: string,
+): string | null => {
+ if (!expiresAt) {
+ return null;
+ }
+ const days = DateTime.fromISO(expiresAt).diff(DateTime.fromISO(createdAt), [
+ 'days',
+ ]).days;
+ return DateTime.utc().plus({ days }).toISO();
+};
diff --git a/front/src/modules/settings/developers/utils/format-expiration.ts b/front/src/modules/settings/developers/utils/format-expiration.ts
new file mode 100644
index 00000000000..ecdd62e1de1
--- /dev/null
+++ b/front/src/modules/settings/developers/utils/format-expiration.ts
@@ -0,0 +1,31 @@
+import { ApiFieldItem } from '@/settings/developers/types/ApiFieldItem';
+import { GetApiKeysQuery } from '~/generated/graphql';
+import { beautifyDateDiff } from '~/utils/date-utils';
+
+export const formatExpiration = (
+ expiresAt: string | null,
+ withExpiresMention: boolean = false,
+ short: boolean = true,
+) => {
+ if (expiresAt) {
+ const dateDiff = beautifyDateDiff(expiresAt, undefined, short);
+ if (dateDiff.includes('-')) {
+ return 'Expired';
+ }
+ return withExpiresMention ? `Expires in ${dateDiff}` : `In ${dateDiff}`;
+ }
+ return withExpiresMention ? 'Never expires' : 'Never';
+};
+
+export const formatExpirations = (
+ apiKeysQuery: GetApiKeysQuery,
+): ApiFieldItem[] => {
+ return apiKeysQuery.findManyApiKey.map(({ id, name, expiresAt }) => {
+ return {
+ id,
+ name,
+ expiration: formatExpiration(expiresAt || null),
+ type: 'internal',
+ };
+ });
+};
diff --git a/front/src/modules/ui/display/icon/index.ts b/front/src/modules/ui/display/icon/index.ts
index e50dd47f401..66a372139b2 100644
--- a/front/src/modules/ui/display/icon/index.ts
+++ b/front/src/modules/ui/display/icon/index.ts
@@ -76,6 +76,7 @@ export {
IconPlug,
IconPlus,
IconProgressCheck,
+ IconRepeat,
IconRobot,
IconSearch,
IconSettings,
diff --git a/front/src/modules/ui/input/components/Select.tsx b/front/src/modules/ui/input/components/Select.tsx
index 6fb077372b5..70bd59b3e32 100644
--- a/front/src/modules/ui/input/components/Select.tsx
+++ b/front/src/modules/ui/input/components/Select.tsx
@@ -11,7 +11,7 @@ import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
import { SelectHotkeyScope } from '../types/SelectHotkeyScope';
-export type SelectProps<Value extends string | number> = {
+export type SelectProps<Value extends string | number | null> = {
dropdownScopeId: string;
onChange: (value: Value) => void;
options: { value: Value; label: string; Icon?: IconComponent }[];
@@ -38,7 +38,7 @@ const StyledLabel = styled.div`
gap: ${({ theme }) => theme.spacing(1)};
`;
-export const Select = <Value extends string | number>({
+export const Select = <Value extends string | number | null>({
dropdownScopeId,
onChange,
options,
diff --git a/front/src/modules/ui/input/components/TextInput.tsx b/front/src/modules/ui/input/components/TextInput.tsx
index 406145148ea..23a01f2bd1c 100644
--- a/front/src/modules/ui/input/components/TextInput.tsx
+++ b/front/src/modules/ui/input/components/TextInput.tsx
@@ -25,7 +25,6 @@ export type TextInputComponentProps = Omit<
> & {
className?: string;
label?: string;
- info?: string;
onChange?: (text: string) => void;
fullWidth?: boolean;
disableHotkeys?: boolean;
@@ -46,13 +45,6 @@ const StyledLabel = styled.span`
text-transform: uppercase;
`;
-const StyledInfo = styled.span`
- color: ${({ theme }) => theme.font.color.light};
- font-size: ${({ theme }) => theme.font.size.sm};
- font-weight: ${({ theme }) => theme.font.weight.regular};
- margin-top: ${({ theme }) => theme.spacing(1)};
-`;
-
const StyledInputContainer = styled.div`
display: flex;
flex-direction: row;
@@ -120,7 +112,6 @@ const TextInputComponent = (
{
className,
label,
- info,
value,
onChange,
onFocus,
@@ -212,7 +203,6 @@ const TextInputComponent = (
)}
</StyledTrailingIconContainer>
</StyledInputContainer>
- {info && <StyledInfo>{info}</StyledInfo>}
{error && <StyledErrorHelper>{error}</StyledErrorHelper>}
</StyledContainer>
);
diff --git a/front/src/modules/ui/input/components/__stories__/Select.stories.tsx b/front/src/modules/ui/input/components/__stories__/Select.stories.tsx
index ae118a00a6b..90b167bf079 100644
--- a/front/src/modules/ui/input/components/__stories__/Select.stories.tsx
+++ b/front/src/modules/ui/input/components/__stories__/Select.stories.tsx
@@ -6,11 +6,11 @@ import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
import { Select, SelectProps } from '../Select';
-type RenderProps = SelectProps<string | number>;
+type RenderProps = SelectProps<string | number | null>;
const Render = (args: RenderProps) => {
const [value, setValue] = useState(args.value);
- const handleChange = (value: string | number) => {
+ const handleChange = (value: string | number | null) => {
args.onChange?.(value);
setValue(value);
};
diff --git a/front/src/modules/ui/input/components/__stories__/TextInput.stories.tsx b/front/src/modules/ui/input/components/__stories__/TextInput.stories.tsx
index 5838f0e1f97..74dc2e96bdb 100644
--- a/front/src/modules/ui/input/components/__stories__/TextInput.stories.tsx
+++ b/front/src/modules/ui/input/components/__stories__/TextInput.stories.tsx
@@ -38,7 +38,3 @@ export const Filled: Story = {
export const Disabled: Story = {
args: { disabled: true, value: 'Tim' },
};
-
-export const WithInfo: Story = {
- args: { info: 'Some info displayed below the input', value: 'Tim' },
-};
diff --git a/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeyDetail.tsx b/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeyDetail.tsx
index 1acc6ec0939..04b9efd4384 100644
--- a/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeyDetail.tsx
+++ b/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeyDetail.tsx
@@ -1,11 +1,18 @@
+import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
+import { getOperationName } from '@apollo/client/utilities';
+import styled from '@emotion/styled';
import { useRecoilState } from 'recoil';
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { ApiKeyInput } from '@/settings/developers/components/ApiKeyInput';
-import { generatedApiKeyState } from '@/settings/developers/states/generatedApiKeyState';
-import { IconSettings, IconTrash } from '@/ui/display/icon';
+import { GET_API_KEYS } from '@/settings/developers/graphql/queries/getApiKeys';
+import { useGeneratedApiKeys } from '@/settings/developers/hooks/useGeneratedApiKeys';
+import { generatedApiKeyFamilyState } from '@/settings/developers/states/generatedApiKeyFamilyState';
+import { computeNewExpirationDate } from '@/settings/developers/utils/compute-new-expiration-date';
+import { formatExpiration } from '@/settings/developers/utils/format-expiration';
+import { IconRepeat, IconSettings, IconTrash } from '@/ui/display/icon';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Button } from '@/ui/input/button/components/Button';
import { TextInput } from '@/ui/input/components/TextInput';
@@ -15,62 +22,159 @@ import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import {
useDeleteOneApiKeyMutation,
useGetApiKeyQuery,
+ useInsertOneApiKeyMutation,
} from '~/generated/graphql';
+const StyledInfo = styled.span`
+ color: ${({ theme }) => theme.font.color.light};
+ font-size: ${({ theme }) => theme.font.size.sm};
+ font-weight: ${({ theme }) => theme.font.weight.regular};
+`;
+
+const StyledInputContainer = styled.div`
+ align-items: center;
+ display: flex;
+ flex-direction: row;
+ gap: ${({ theme }) => theme.spacing(2)};
+ width: 100%;
+`;
+
export const SettingsDevelopersApiKeyDetail = () => {
const navigate = useNavigate();
const { apiKeyId = '' } = useParams();
- const [generatedApiKey] = useRecoilState(generatedApiKeyState);
- const apiKeyQuery = useGetApiKeyQuery({
+
+ const setGeneratedApi = useGeneratedApiKeys();
+ const [generatedApiKey] = useRecoilState(
+ generatedApiKeyFamilyState(apiKeyId),
+ );
+
+ const [deleteApiKey] = useDeleteOneApiKeyMutation();
+ const [insertOneApiKey] = useInsertOneApiKeyMutation();
+ const apiKeyData = useGetApiKeyQuery({
variables: {
apiKeyId,
},
- });
- const [deleteApiKey] = useDeleteOneApiKeyMutation();
- const deleteIntegration = async () => {
- await deleteApiKey({ variables: { apiKeyId } });
- navigate('/settings/developers/api-keys');
+ }).data?.findManyApiKey[0];
+
+ const deleteIntegration = async (redirect = true) => {
+ await deleteApiKey({
+ variables: { apiKeyId },
+ refetchQueries: [getOperationName(GET_API_KEYS) ?? ''],
+ });
+ if (redirect) {
+ navigate('/settings/developers/api-keys');
+ }
+ };
+
+ const regenerateApiKey = async () => {
+ if (apiKeyData?.name) {
+ const newExpiresAt = computeNewExpirationDate(
+ apiKeyData.expiresAt,
+ apiKeyData.createdAt,
+ );
+ const apiKey = await insertOneApiKey({
+ variables: {
+ data: {
+ name: apiKeyData.name,
+ expiresAt: newExpiresAt,
+ },
+ },
+ refetchQueries: [getOperationName(GET_API_KEYS) ?? ''],
+ });
+ await deleteIntegration(false);
+ if (apiKey.data?.createOneApiKey) {
+ setGeneratedApi(
+ apiKey.data.createOneApiKey.id,
+ apiKey.data.createOneApiKey.token,
+ );
+ navigate(
+ `/settings/developers/api-keys/${apiKey.data.createOneApiKey.id}`,
+ );
+ }
+ }
};
- const { expiresAt, name } = apiKeyQuery.data?.findManyApiKey[0] || {};
+
+ useEffect(() => {
+ if (apiKeyData) {
+ return () => {
+ setGeneratedApi(apiKeyId, null);
+ };
+ }
+ });
return (
- <SubMenuTopBarContainer Icon={IconSettings} title="Settings">
- <SettingsPageContainer>
- <SettingsHeaderContainer>
- <Breadcrumb
- links={[
- { children: 'APIs', href: '/settings/developers/api-keys' },
- { children: name || '' },
- ]}
- />
- </SettingsHeaderContainer>
- <Section>
- <H2Title
- title="Api Key"
- description="Copy this key as it will only be visible this one time"
- />
- <ApiKeyInput expiresAt={expiresAt} apiKey={generatedApiKey || ''} />
- </Section>
- <Section>
- <H2Title title="Name" description="Name of your API key" />
- <TextInput
- placeholder="E.g. backoffice integration"
- value={name || ''}
- disabled={true}
- fullWidth
- />
- </Section>
- <Section>
- <H2Title title="Danger zone" description="Delete this integration" />
- <Button
- accent="danger"
- variant="secondary"
- title="Disable"
- Icon={IconTrash}
- onClick={deleteIntegration}
- />
- </Section>
- </SettingsPageContainer>
- </SubMenuTopBarContainer>
+ <>
+ {apiKeyData?.name && (
+ <SubMenuTopBarContainer Icon={IconSettings} title="Settings">
+ <SettingsPageContainer>
+ <SettingsHeaderContainer>
+ <Breadcrumb
+ links={[
+ { children: 'APIs', href: '/settings/developers/api-keys' },
+ { children: apiKeyData.name },
+ ]}
+ />
+ </SettingsHeaderContainer>
+ <Section>
+ {generatedApiKey ? (
+ <>
+ <H2Title
+ title="Api Key"
+ description="Copy this key as it will only be visible this one time"
+ />
+ <ApiKeyInput apiKey={generatedApiKey} />
+ <StyledInfo>
+ {formatExpiration(apiKeyData?.expiresAt || '', true, false)}
+ </StyledInfo>
+ </>
+ ) : (
+ <>
+ <H2Title
+ title="Api Key"
+ description="Regenerate an Api key"
+ />
+ <StyledInputContainer>
+ <Button
+ title="Regenerate Key"
+ Icon={IconRepeat}
+ onClick={regenerateApiKey}
+ />
+ <StyledInfo>
+ {formatExpiration(
+ apiKeyData?.expiresAt || '',
+ true,
+ false,
+ )}
+ </StyledInfo>
+ </StyledInputContainer>
+ </>
+ )}
+ </Section>
+ <Section>
+ <H2Title title="Name" description="Name of your API key" />
+ <TextInput
+ placeholder="E.g. backoffice integration"
+ value={apiKeyData.name}
+ disabled
+ fullWidth
+ />
+ </Section>
+ <Section>
+ <H2Title
+ title="Danger zone"
+ description="Delete this integration"
+ />
+ <Button
+ accent="danger"
+ variant="secondary"
+ title="Disable"
+ Icon={IconTrash}
+ onClick={() => deleteIntegration()}
+ />
+ </Section>
+ </SettingsPageContainer>
+ </SubMenuTopBarContainer>
+ )}
+ </>
);
};
diff --git a/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeys.tsx b/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeys.tsx
index 9b1fbe54014..ec43cfb7393 100644
--- a/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeys.tsx
+++ b/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeys.tsx
@@ -3,7 +3,7 @@ import styled from '@emotion/styled';
import { objectSettingsWidth } from '@/settings/data-model/constants/objectSettings';
import { SettingsApiKeysFieldItemTableRow } from '@/settings/developers/components/SettingsApiKeysFieldItemTableRow';
-import { activeApiKeyItems } from '@/settings/developers/constants/mockObjects';
+import { formatExpirations } from '@/settings/developers/utils/format-expiration';
import { IconPlus, IconSettings } from '@/ui/display/icon';
import { H1Title } from '@/ui/display/typography/components/H1Title';
import { H2Title } from '@/ui/display/typography/components/H2Title';
@@ -12,6 +12,7 @@ import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer'
import { Table } from '@/ui/layout/table/components/Table';
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
import { TableRow } from '@/ui/layout/table/components/TableRow';
+import { useGetApiKeysQuery } from '~/generated/graphql';
const StyledContainer = styled.div`
height: fit-content;
@@ -36,6 +37,8 @@ const StyledH1Title = styled(H1Title)`
export const SettingsDevelopersApiKeys = () => {
const navigate = useNavigate();
+ const apiKeysQuery = useGetApiKeysQuery();
+ const apiKeys = apiKeysQuery.data ? formatExpirations(apiKeysQuery.data) : [];
return (
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
@@ -63,10 +66,13 @@ export const SettingsDevelopersApiKeys = () => {
<TableHeader>Expiration</TableHeader>
<TableHeader></TableHeader>
</StyledTableRow>
- {activeApiKeyItems.map((fieldItem) => (
+ {apiKeys.map((fieldItem) => (
<SettingsApiKeysFieldItemTableRow
key={fieldItem.id}
fieldItem={fieldItem}
+ onClick={() => {
+ navigate(`/settings/developers/api-keys/${fieldItem.id}`);
+ }}
/>
))}
</Table>
diff --git a/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeysNew.tsx b/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeysNew.tsx
index 548f3cb562c..3e20d268874 100644
--- a/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeysNew.tsx
+++ b/front/src/pages/settings/developers/api-keys/SettingsDevelopersApiKeysNew.tsx
@@ -1,13 +1,14 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
+import { getOperationName } from '@apollo/client/utilities';
import { DateTime } from 'luxon';
-import { useRecoilState } from 'recoil';
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons';
import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { ExpirationDates } from '@/settings/developers/constants/expirationDates';
-import { generatedApiKeyState } from '@/settings/developers/states/generatedApiKeyState';
+import { GET_API_KEYS } from '@/settings/developers/graphql/queries/getApiKeys';
+import { useGeneratedApiKeys } from '@/settings/developers/hooks/useGeneratedApiKeys';
import { IconSettings } from '@/ui/display/icon';
import { H2Title } from '@/ui/display/typography/components/H2Title';
import { Select } from '@/ui/input/components/Select';
@@ -20,10 +21,10 @@ import { useInsertOneApiKeyMutation } from '~/generated/graphql';
export const SettingsDevelopersApiKeysNew = () => {
const [insertOneApiKey] = useInsertOneApiKeyMutation();
const navigate = useNavigate();
- const [, setGeneratedApiKey] = useRecoilState(generatedApiKeyState);
+ const setGeneratedApi = useGeneratedApiKeys();
const [formValues, setFormValues] = useState<{
name: string;
- expirationDate: number;
+ expirationDate: number | null;
}>({
expirationDate: ExpirationDates[0].value,
name: '',
@@ -33,16 +34,24 @@ export const SettingsDevelopersApiKeysNew = () => {
variables: {
data: {
name: formValues.name,
- expiresAt: DateTime.now()
- .plus({ days: formValues.expirationDate })
- .toISODate(),
+ expiresAt: formValues.expirationDate
+ ? DateTime.now()
+ .plus({ days: formValues.expirationDate })
+ .toISODate()
+ : null,
},
},
+ refetchQueries: [getOperationName(GET_API_KEYS) ?? ''],
});
- setGeneratedApiKey(apiKey.data?.createOneApiKey?.token);
- navigate(
- `/settings/developers/api-keys/${apiKey.data?.createOneApiKey?.id}`,
- );
+ if (apiKey.data?.createOneApiKey) {
+ setGeneratedApi(
+ apiKey.data.createOneApiKey.id,
+ apiKey.data.createOneApiKey.token,
+ );
+ navigate(
+ `/settings/developers/api-keys/${apiKey.data.createOneApiKey.id}`,
+ );
+ }
};
const canSave = !!formValues.name;
return (
diff --git a/front/src/pages/settings/developers/api-keys/__stories__/SettingsDevelopersApiKeysDetail.stories.tsx b/front/src/pages/settings/developers/api-keys/__stories__/SettingsDevelopersApiKeysDetail.stories.tsx
index a01b14b8dd1..64a1c04d9aa 100644
--- a/front/src/pages/settings/developers/api-keys/__stories__/SettingsDevelopersApiKeysDetail.stories.tsx
+++ b/front/src/pages/settings/developers/api-keys/__stories__/SettingsDevelopersApiKeysDetail.stories.tsx
@@ -6,7 +6,6 @@ import {
PageDecoratorArgs,
} from '~/testing/decorators/PageDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
-import { mockedApiKeyToken } from '~/testing/mock-data/api-keys';
import { sleep } from '~/testing/sleep';
const meta: Meta<PageDecoratorArgs> = {
@@ -15,7 +14,6 @@ const meta: Meta<PageDecoratorArgs> = {
decorators: [PageDecorator],
args: {
routePath: '/settings/apis/f7c6d736-8fcd-4e9c-ab99-28f6a9031570',
- state: mockedApiKeyToken,
},
parameters: {
msw: graphqlMocks,
diff --git a/front/src/testing/decorators/PageDecorator.tsx b/front/src/testing/decorators/PageDecorator.tsx
index 714e12e09a3..4badb6e0b3d 100644
--- a/front/src/testing/decorators/PageDecorator.tsx
+++ b/front/src/testing/decorators/PageDecorator.tsx
@@ -11,38 +11,29 @@ import { FullHeightStorybookLayout } from '../FullHeightStorybookLayout';
export type PageDecoratorArgs = {
routePath: string;
routeParams: RouteParams;
- state?: string;
};
type RouteParams = {
[param: string]: string;
};
-const computeLocation = (
- routePath: string,
- routeParams: RouteParams,
- state?: string,
-) => {
+const computeLocation = (routePath: string, routeParams: RouteParams) => {
return {
pathname: routePath.replace(
/:(\w+)/g,
(paramName) => routeParams[paramName] ?? '',
),
- state,
};
};
export const PageDecorator: Decorator<{
routePath: string;
routeParams: RouteParams;
- state?: string;
}> = (Story, { args }) => (
<UserProvider>
<ClientConfigProvider>
<MemoryRouter
- initialEntries={[
- computeLocation(args.routePath, args.routeParams, args.state),
- ]}
+ initialEntries={[computeLocation(args.routePath, args.routeParams)]}
>
<FullHeightStorybookLayout>
<HelmetProvider>
diff --git a/front/src/testing/graphqlMocks.ts b/front/src/testing/graphqlMocks.ts
index 7a0d092b9e9..68815f745e5 100644
--- a/front/src/testing/graphqlMocks.ts
+++ b/front/src/testing/graphqlMocks.ts
@@ -18,6 +18,7 @@ import { SEARCH_COMPANY_QUERY } from '@/search/graphql/queries/searchCompanyQuer
import { SEARCH_PEOPLE_QUERY } from '@/search/graphql/queries/searchPeopleQuery';
import { SEARCH_USER_QUERY } from '@/search/graphql/queries/searchUserQuery';
import { GET_API_KEY } from '@/settings/developers/graphql/queries/getApiKey';
+import { GET_API_KEYS } from '@/settings/developers/graphql/queries/getApiKeys';
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
import { GET_VIEW_FIELDS } from '@/views/graphql/queries/getViewFields';
import { GET_VIEWS } from '@/views/graphql/queries/getViews';
@@ -283,7 +284,14 @@ export const graphqlMocks = [
graphql.query(getOperationName(GET_API_KEY) ?? '', (req, res, ctx) => {
return res(
ctx.data({
- findManyApiKey: mockedApiKeys[0],
+ findManyApiKey: [mockedApiKeys[0]],
+ }),
+ );
+ }),
+ graphql.query(getOperationName(GET_API_KEYS) ?? '', (req, res, ctx) => {
+ return res(
+ ctx.data({
+ findManyApiKey: mockedApiKeys,
}),
);
}),
diff --git a/front/src/testing/mock-data/api-keys.ts b/front/src/testing/mock-data/api-keys.ts
index f9d7bd96125..dd8b41c635b 100644
--- a/front/src/testing/mock-data/api-keys.ts
+++ b/front/src/testing/mock-data/api-keys.ts
@@ -4,8 +4,6 @@ type MockedApiKey = Pick<
ApiKey,
'id' | 'name' | 'createdAt' | 'updatedAt' | 'expiresAt' | '__typename'
>;
-export const mockedApiKeyToken =
- 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0d2VudHktN2VkOWQyMTItMWMyNS00ZDAyLWJmMjUtNmFlY2NmN2VhNDE5IiwiaWF0IjoxNjk4MDkzMDU0LCJleHAiOjE2OTkzMTUxOTksImp0aSI6IjY0Njg3ZWNmLWFhYzktNDNmYi1hY2I4LTE1M2QzNzgwYmIzMSJ9.JkQ3u7aRiqOFQkgHcC-mgCU37096HRSo40A_9X8gEng';
export const mockedApiKeys: Array<MockedApiKey> = [
{
id: 'f7c6d736-8fcd-4e9c-ab99-28f6a9031570',
@@ -15,4 +13,20 @@ export const mockedApiKeys: Array<MockedApiKey> = [
expiresAt: '2100-11-06T23:59:59.825Z',
__typename: 'ApiKey',
},
+ {
+ id: 'f7c6d736-8fcd-4e9c-ab99-28f6a9031571',
+ name: 'Gmail Integration',
+ createdAt: '2023-04-26T10:12:42.33625+00:00',
+ updatedAt: '2023-04-26T10:23:42.33625+00:00',
+ expiresAt: null,
+ __typename: 'ApiKey',
+ },
+ {
+ id: 'f7c6d736-8fcd-4e9c-ab99-28f6a9031572',
+ name: 'Github Integration',
+ createdAt: '2023-04-26T10:12:42.33625+00:00',
+ updatedAt: '2023-04-26T10:23:42.33625+00:00',
+ expiresAt: '2022-11-06T23:59:59.825Z',
+ __typename: 'ApiKey',
+ },
];
diff --git a/front/src/utils/__tests__/date-utils.test.ts b/front/src/utils/__tests__/date-utils.test.ts
index e287c8bb27c..3c96e6293a0 100644
--- a/front/src/utils/__tests__/date-utils.test.ts
+++ b/front/src/utils/__tests__/date-utils.test.ts
@@ -14,6 +14,7 @@ import {
import { logError } from '../logError';
jest.mock('~/utils/logError');
+jest.useFakeTimers().setSystemTime(new Date('2024-01-01T00:00:00.000Z'));
describe('beautifyExactDateTime', () => {
it('should return the date in the correct format with time', () => {
@@ -277,8 +278,20 @@ describe('beautifyDateDiff', () => {
expect(result).toEqual('1 year and 2 days');
});
it('should compare to now', () => {
- const date = '2200-11-01T00:00:00.000Z';
+ const date = '2027-01-10T00:00:00.000Z';
const result = beautifyDateDiff(date);
- expect(result).toContain('years');
+ expect(result).toEqual('3 years and 9 days');
+ });
+ it('should return short version', () => {
+ const date = '2033-11-05T00:00:00.000Z';
+ const dateToCompareWith = '2023-11-01T00:00:00.000Z';
+ const result = beautifyDateDiff(date, dateToCompareWith, true);
+ expect(result).toEqual('10 years');
+ });
+ it('should return short version for short differences', () => {
+ const date = '2023-11-05T00:00:00.000Z';
+ const dateToCompareWith = '2023-11-01T00:00:00.000Z';
+ const result = beautifyDateDiff(date, dateToCompareWith, true);
+ expect(result).toEqual('4 days');
});
});
diff --git a/front/src/utils/date-utils.ts b/front/src/utils/date-utils.ts
index d82e2fbb852..57fbf67a99c 100644
--- a/front/src/utils/date-utils.ts
+++ b/front/src/utils/date-utils.ts
@@ -109,7 +109,11 @@ export const hasDatePassed = (date: Date | string | number) => {
}
};
-export const beautifyDateDiff = (date: string, dateToCompareWith?: string) => {
+export const beautifyDateDiff = (
+ date: string,
+ dateToCompareWith?: string,
+ short: boolean = false,
+) => {
const dateDiff = DateTime.fromISO(date).diff(
dateToCompareWith ? DateTime.fromISO(dateToCompareWith) : DateTime.now(),
['years', 'days'],
@@ -117,6 +121,7 @@ export const beautifyDateDiff = (date: string, dateToCompareWith?: string) => {
let result = '';
if (dateDiff.years) result = result + `${dateDiff.years} year`;
if (![0, 1].includes(dateDiff.years)) result = result + 's';
+ if (short && dateDiff.years) return result;
if (dateDiff.years && dateDiff.days) result = result + ' and ';
if (dateDiff.days) result = result + `${Math.floor(dateDiff.days)} day`;
if (![0, 1].includes(dateDiff.days)) result = result + 's';
diff --git a/server/.env.example b/server/.env.example
index 061db59ecb3..47f7b64d966 100644
--- a/server/.env.example
+++ b/server/.env.example
@@ -14,7 +14,7 @@ SIGN_IN_PREFILLED=true
# DEBUG_MODE=true
# ACCESS_TOKEN_EXPIRES_IN=30m
# LOGIN_TOKEN_EXPIRES_IN=15m
-# API_TOKEN_EXPIRES_IN=2y
+# API_TOKEN_EXPIRES_IN=1000y
# REFRESH_TOKEN_EXPIRES_IN=90d
# FRONT_AUTH_CALLBACK_URL=http://localhost:3001/verify
# AUTH_GOOGLE_ENABLED=false
diff --git a/server/src/integrations/environment/environment.service.ts b/server/src/integrations/environment/environment.service.ts
index 82096a4f94e..10671206e65 100644
--- a/server/src/integrations/environment/environment.service.ts
+++ b/server/src/integrations/environment/environment.service.ts
@@ -86,7 +86,7 @@ export class EnvironmentService {
}
getApiTokenExpiresIn(): string {
- return this.configService.get<string>('API_TOKEN_EXPIRES_IN') ?? '2y';
+ return this.configService.get<string>('API_TOKEN_EXPIRES_IN') ?? '1000y';
}
getFrontAuthCallbackUrl(): string {