Fix Activities and Tasks modules (#2561)

* Fix activities

* Fix Timeline

* Refactor useCreateOne and useUpdateOne records

* Fix seeds
This commit is contained in:
Charles Bochet
2023-11-17 16:24:58 +01:00
committed by GitHub
parent a6d8cdb116
commit baf1260443
23 changed files with 259 additions and 222 deletions

View File

@ -18,6 +18,7 @@ import { useSnackBar } from '@/ui/feedback/snack-bar/hooks/useSnackBar';
import { MainButton } from '@/ui/input/button/components/MainButton';
import { TextInput } from '@/ui/input/components/TextInput';
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
import { WorkspaceMember } from '@/workspace-member/types/WorkspaceMember';
const StyledContentContainer = styled.div`
width: 100%;
@ -59,7 +60,7 @@ export const CreateProfile = () => {
);
const { updateOneObject, objectNotFoundInMetadata } =
useUpdateOneObjectRecord({
useUpdateOneObjectRecord<WorkspaceMember>({
objectNameSingular: 'workspaceMemberV2',
});
@ -91,7 +92,7 @@ export const CreateProfile = () => {
throw new Error('Object not found in metadata');
}
const result = await updateOneObject({
await updateOneObject({
idToUpdate: currentWorkspaceMember?.id,
input: {
firstName: data.firstName,
@ -99,10 +100,6 @@ export const CreateProfile = () => {
},
});
if (result.errors || !result.data?.updateWorkspaceMemberV2) {
throw result.errors ?? new Error('Unknown error');
}
setCurrentWorkspaceMember(
(current) =>
({

View File

@ -33,7 +33,7 @@ export const SettingsNewObject = () => {
} = useObjectMetadataItemForSettings();
const { createOneObject: createOneView } = useCreateOneObjectRecord({
objectNamePlural: 'viewsV2',
objectNameSingular: 'viewV2',
});
const [

View File

@ -45,7 +45,7 @@ export const SettingsObjectNewFieldStep2 = () => {
const [objectViews, setObjectViews] = useState<View[]>([]);
const { createOneObject: createOneViewField } = useCreateOneObjectRecord({
objectNamePlural: 'viewFieldsV2',
objectNameSingular: 'viewFieldV2',
});
useFindManyObjectRecords({

View File

@ -21,7 +21,7 @@ import { TextInput } from '@/ui/input/components/TextInput';
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 { useGenerateOneApiKeyTokenMutation } from '~/generated/graphql';
import { ApiKey, useGenerateOneApiKeyTokenMutation } from '~/generated/graphql';
const StyledInfo = styled.span`
color: ${({ theme }) => theme.font.color.light};
@ -47,11 +47,13 @@ export const SettingsDevelopersApiKeyDetail = () => {
);
const [generateOneApiKeyToken] = useGenerateOneApiKeyTokenMutation();
const { createOneObject: createOneApiKey } = useCreateOneObjectRecord({
objectNamePlural: 'apiKeysV2',
});
const { updateOneObject: updateApiKey } = useUpdateOneObjectRecord({
objectNamePlural: 'apiKeysV2',
const { createOneObject: createOneApiKey } = useCreateOneObjectRecord<ApiKey>(
{
objectNameSingular: 'apiKeyV2',
},
);
const { updateOneObject: updateApiKey } = useUpdateOneObjectRecord<ApiKey>({
objectNameSingular: 'apiKeyV2',
});
const { object: apiKeyData } = useFindOneObjectRecord({
@ -77,17 +79,22 @@ export const SettingsDevelopersApiKeyDetail = () => {
name: name,
expiresAt: newExpiresAt,
});
if (!newApiKey) {
return;
}
const tokenData = await generateOneApiKeyToken({
variables: {
data: {
id: newApiKey.createApiKeyV2.id,
expiresAt: newApiKey.createApiKeyV2.expiresAt,
name: newApiKey.createApiKeyV2.name, // TODO update typing to remove useless name param here
id: newApiKey.id,
expiresAt: newApiKey.expiresAt,
name: newApiKey.name, // TODO update typing to remove useless name param here
},
},
});
return {
id: newApiKey.createApiKeyV2.id,
id: newApiKey.id,
token: tokenData.data?.generateApiKeyV2Token.token,
};
};
@ -100,7 +107,8 @@ export const SettingsDevelopersApiKeyDetail = () => {
);
const apiKey = await createIntegration(apiKeyData.name, newExpiresAt);
await deleteIntegration(false);
if (apiKey.token) {
if (apiKey && apiKey.token) {
setGeneratedApi(apiKey.id, apiKey.token);
navigate(`/settings/developers/api-keys/${apiKey.id}`);
}

View File

@ -15,7 +15,7 @@ import { TextInput } from '@/ui/input/components/TextInput';
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 { useGenerateOneApiKeyTokenMutation } from '~/generated/graphql';
import { ApiKey, useGenerateOneApiKeyTokenMutation } from '~/generated/graphql';
export const SettingsDevelopersApiKeysNew = () => {
const [generateOneApiKeyToken] = useGenerateOneApiKeyTokenMutation();
@ -29,9 +29,11 @@ export const SettingsDevelopersApiKeysNew = () => {
name: '',
});
const { createOneObject: createOneApiKey } = useCreateOneObjectRecord({
objectNamePlural: 'apiKeysV2',
});
const { createOneObject: createOneApiKey } = useCreateOneObjectRecord<ApiKey>(
{
objectNameSingular: 'apiKeyV2',
},
);
const onSave = async () => {
const expiresAt = formValues.expirationDate
? DateTime.now().plus({ days: formValues.expirationDate }).toString()
@ -40,21 +42,23 @@ export const SettingsDevelopersApiKeysNew = () => {
name: formValues.name,
expiresAt,
});
if (!newApiKey) {
return;
}
const tokenData = await generateOneApiKeyToken({
variables: {
data: {
id: newApiKey.createApiKeyV2.id,
expiresAt: newApiKey.createApiKeyV2.expiresAt,
name: newApiKey.createApiKeyV2.name, // TODO update typing to remove useless name param here
id: newApiKey.id,
expiresAt: newApiKey.expiresAt,
name: newApiKey.name, // TODO update typing to remove useless name param here
},
},
});
if (tokenData.data?.generateApiKeyV2Token) {
setGeneratedApi(
newApiKey.createApiKeyV2.id,
tokenData.data.generateApiKeyV2Token.token,
);
navigate(`/settings/developers/api-keys/${newApiKey.createApiKeyV2.id}`);
setGeneratedApi(newApiKey.id, tokenData.data.generateApiKeyV2Token.token);
navigate(`/settings/developers/api-keys/${newApiKey.id}`);
}
};
const canSave = !!formValues.name && createOneApiKey;