Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(soup): use query mutation for task mark-as-done (#997)

Seamus4b0f08454ef0
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index e6956135a5..da76af19fb 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -19,10 +19,8 @@ import { type EntityData, isTaskEntity } from '@macro-entity';
import { entityHasUnreadNotifications } from '@notifications';
import type { PreviewViewStandardLabel } from '@service-email/generated/schemas';
import { useTutorialCompleted } from '@service-gql/client';
-import {
- type PropertiesEntityType,
- propertiesServiceClient,
-} from '@service-properties/client';
+import type { PropertiesEntityType } from '@service-properties/client';
+import { useSetPropertyStatusCompleteMutation } from '@queries/properties/entity';
import { storageServiceClient } from '@service-storage/client';
import { createLazyMemo } from '@solid-primitives/memo';
import { useQuery } from '@tanstack/solid-query';
@@ -445,6 +443,9 @@ export function createNavigationEntityListShortcut({
return undefined;
};
+ const setPropertyStatusCompleteMutation =
+ useSetPropertyStatusCompleteMutation();
+
actionRegistry.register(
'mark_as_done',
async (multiSelectEntities) => {
@@ -517,14 +518,10 @@ export function createNavigationEntityListShortcut({
}
const entityType = getPropertiesEntityType(entity);
if (entityType) {
- propertiesServiceClient
- .setPropertyStatusComplete({
- entity_type: entityType,
- entity_id: entity.id,
- })
- .catch((err) =>
- console.error('Failed to set status complete', err)
- );
+ setPropertyStatusCompleteMutation.mutate({
+ entityType,
+ entityId: entity.id,
+ });
}
}
diff --git a/js/app/packages/queries/properties/entity.ts b/js/app/packages/queries/properties/entity.ts
index 438de9e7c1..8448b7a5bd 100644
--- a/js/app/packages/queries/properties/entity.ts
+++ b/js/app/packages/queries/properties/entity.ts
@@ -10,7 +10,10 @@ import type {
Property,
PropertyApiValues,
} from '../../core/component/Properties/types';
-import { propertiesServiceClient } from '../../service-clients/service-properties/client';
+import {
+ type PropertiesEntityType,
+ propertiesServiceClient,
+} from '../../service-clients/service-properties/client';
import type { EntityType } from '../../service-clients/service-properties/generated/schemas/entityType';
import { queryClient } from '../client';
import { type MutationCallbacks, withCallbacks } from '../utils';
@@ -197,3 +200,39 @@ export function useAddEntityPropertyMutation(
),
}));
}
+
+export type SetPropertyStatusCompleteParams = {
+ entityType: PropertiesEntityType;
+ entityId: string;
+};
+
+/** Sets the status property to complete for an entity (mark as done) */
+export function useSetPropertyStatusCompleteMutation(
+ callbacks?: MutationCallbacks<void, Error, SetPropertyStatusCompleteParams>
+) {
+ return useMutation(() => ({
+ mutationFn: async (vars: SetPropertyStatusCompleteParams) => {
+ await throwOnErr(
+ async () =>
+ await propertiesServiceClient.setPropertyStatusComplete({
+ entity_type: vars.entityType,
+ entity_id: vars.entityId,
+ })
+ );
+ },
+ ...withCallbacks<void, Error, SetPropertyStatusCompleteParams>(
+ {
+ onError(error) {
+ console.error('Failed to set status complete', error);
+ },
+ onSettled: (_data, _error, variables) => {
+ invalidatePropertiesForEntity(
+ variables.entityType,
+ variables.entityId
+ );
+ },
+ },
+ callbacks
+ ),
+ }));
+}