Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions Clients/src/application/hooks/useTaskEntityLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {
useQuery,
useMutation,
useQueryClient,
UseQueryResult,
} from "@tanstack/react-query";
import {
getTaskEntityLinks,
addTaskEntityLink,
removeTaskEntityLink,
ITaskEntityLink,
EntityType,
} from "../repository/taskEntityLink.repository";

// Query keys for task entity links
export const taskEntityLinkQueryKeys = {
all: ["taskEntityLinks"] as const,
byTask: (taskId: number) =>
[...taskEntityLinkQueryKeys.all, "byTask", taskId] as const,
};

/**
* Hook to fetch entity links for a task
*/
export const useTaskEntityLinks = (
taskId: number | undefined
): UseQueryResult<ITaskEntityLink[], Error> => {
return useQuery({
queryKey: taskEntityLinkQueryKeys.byTask(taskId!),
queryFn: async () => {
if (!taskId) return [];
return await getTaskEntityLinks(taskId);
},
enabled: !!taskId,
staleTime: 2 * 60 * 1000, // 2 minutes
gcTime: 5 * 60 * 1000, // 5 minutes
});
};

/**
* Hook to add an entity link to a task
*/
export const useAddTaskEntityLink = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async ({
taskId,
entityId,
entityType,
}: {
taskId: number;
entityId: number;
entityType: EntityType;
}) => {
return await addTaskEntityLink(taskId, entityId, entityType);
},
onSuccess: (_, { taskId }) => {
queryClient.invalidateQueries({
queryKey: taskEntityLinkQueryKeys.byTask(taskId),
});
},
});
};

/**
* Hook to remove an entity link from a task
*/
export const useRemoveTaskEntityLink = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async ({ taskId, linkId }: { taskId: number; linkId: number }) => {
await removeTaskEntityLink(taskId, linkId);
},
onSuccess: (_, { taskId }) => {
queryClient.invalidateQueries({
queryKey: taskEntityLinkQueryKeys.byTask(taskId),
});
},
});
};

export type { ITaskEntityLink, EntityType };
90 changes: 69 additions & 21 deletions Clients/src/application/repository/intakeForm.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IntakeEntityType,
IntakeSubmissionStatus,
} from "../../domain/intake/enums";
import type { FieldType, FormDesignSettings } from "../../presentation/pages/IntakeFormBuilder/types";

// Re-export enums for convenience
export { IntakeFormStatus, IntakeEntityType, IntakeSubmissionStatus };
Expand Down Expand Up @@ -39,7 +40,7 @@ export interface FieldValidation {
*/
export interface FormField {
id: string;
type: string;
type: FieldType;
label: string;
placeholder?: string;
helpText?: string;
Expand Down Expand Up @@ -78,7 +79,7 @@ export interface IntakeForm {
riskAssessmentConfig?: Record<string, unknown> | null;
llmKeyId?: number | null;
suggestedQuestionsEnabled?: boolean;
designSettings?: Record<string, unknown> | null;
designSettings?: FormDesignSettings | null;
createdBy: number;
createdAt: Date;
updatedAt: Date;
Expand Down Expand Up @@ -165,7 +166,7 @@ export async function getAllIntakeForms(

const url = `${BASE_URL}/forms${queryParams.toString() ? `?${queryParams}` : ""}`;
const response = await apiServices.get(url, { signal });
return response.data;
return response.data as { data: IntakeForm[]; pagination?: { total: number; page: number; limit: number } };
}

/**
Expand All @@ -176,7 +177,7 @@ export async function getIntakeForm(
signal?: AbortSignal
): Promise<{ data: IntakeForm }> {
const response = await apiServices.get(`${BASE_URL}/forms/${formId}`, { signal });
return response.data;
return response.data as { data: IntakeForm };
}

/**
Expand All @@ -196,12 +197,12 @@ export async function createIntakeForm(
riskTierSystem?: string;
llmKeyId?: number | null;
suggestedQuestionsEnabled?: boolean;
designSettings?: Record<string, unknown> | null;
designSettings?: FormDesignSettings | null;
},
signal?: AbortSignal
): Promise<{ data: IntakeForm }> {
const response = await apiServices.post(`${BASE_URL}/forms`, data, { signal });
return response.data;
return response.data as { data: IntakeForm };
}

/**
Expand All @@ -221,12 +222,12 @@ export async function updateIntakeForm(
riskTierSystem?: string;
llmKeyId?: number | null;
suggestedQuestionsEnabled?: boolean;
designSettings?: Record<string, unknown> | null;
designSettings?: FormDesignSettings | null;
},
signal?: AbortSignal
): Promise<{ data: IntakeForm }> {
const response = await apiServices.patch(`${BASE_URL}/forms/${formId}`, data, { signal });
return response.data;
return response.data as { data: IntakeForm };
}

/**
Expand All @@ -237,7 +238,7 @@ export async function deleteIntakeForm(
signal?: AbortSignal
): Promise<{ data: null }> {
const response = await apiServices.delete(`${BASE_URL}/forms/${formId}`, { signal });
return response.data;
return response.data as { data: null };
}

/**
Expand All @@ -248,7 +249,7 @@ export async function archiveIntakeForm(
signal?: AbortSignal
): Promise<{ data: IntakeForm }> {
const response = await apiServices.post(`${BASE_URL}/forms/${formId}/archive`, undefined, { signal });
return response.data;
return response.data as { data: IntakeForm };
}

// ============================================================================
Expand All @@ -273,7 +274,7 @@ export async function getPendingSubmissions(

const url = `${BASE_URL}/submissions${queryParams.toString() ? `?${queryParams}` : ""}`;
const response = await apiServices.get(url, { signal });
return response.data;
return response.data as { data: IntakeSubmission[]; pagination?: { total: number; page: number; limit: number } };
}

/**
Expand All @@ -299,7 +300,22 @@ export async function getSubmissionPreview(
};
}> {
const response = await apiServices.get(`${BASE_URL}/submissions/${submissionId}/preview`, { signal });
return response.data;
return response.data as {
data: {
submission: IntakeSubmission;
riskAssessment: RiskAssessment | null;
entityPreview: Record<string, unknown>;
form: {
id: number;
name: string;
entityType: string;
schema: FormSchema;
riskTierSystem?: string;
};
riskTier?: string | null;
riskOverride?: RiskOverride | null;
};
};
}

/**
Expand All @@ -322,7 +338,7 @@ export async function approveSubmission(
data || {},
{ signal }
);
return response.data;
return response.data as { data: { submission: IntakeSubmission; createdEntity: unknown } };
}

/**
Expand All @@ -338,7 +354,7 @@ export async function rejectSubmission(
{ reason },
{ signal }
);
return response.data;
return response.data as { data: IntakeSubmission };
}

// ============================================================================
Expand All @@ -350,7 +366,7 @@ export async function rejectSubmission(
*/
export async function getCaptcha(): Promise<{ data: { question: string; token: string } }> {
const response = await apiServices.get(`${BASE_URL}/public/captcha`);
return response.data;
return response.data as { data: { question: string; token: string } };
}

/**
Expand All @@ -370,7 +386,7 @@ export async function getPublicForm(
entityType: IntakeEntityType;
schema: FormSchema;
submitButtonText: string;
designSettings?: Record<string, unknown> | null;
designSettings?: FormDesignSettings | null;
};
previousData?: Record<string, unknown>;
previousSubmitterName?: string;
Expand All @@ -379,7 +395,23 @@ export async function getPublicForm(
}> {
const queryParams = resubmissionToken ? `?token=${resubmissionToken}` : "";
const response = await apiServices.get(`${BASE_URL}/public/${tenantSlug}/${formSlug}${queryParams}`);
return response.data;
return response.data as {
data: {
form: {
id: number;
name: string;
description: string;
slug: string;
entityType: IntakeEntityType;
schema: FormSchema;
submitButtonText: string;
designSettings?: FormDesignSettings | null;
};
previousData?: Record<string, unknown>;
previousSubmitterName?: string;
previousSubmitterEmail?: string;
};
};
}

/**
Expand All @@ -404,7 +436,7 @@ export async function submitPublicForm(
};
}> {
const response = await apiServices.post(`${BASE_URL}/public/${tenantSlug}/${formSlug}`, data);
return response.data;
return response.data as { data: { submissionId: number; resubmissionToken: string; message: string } };
}

/**
Expand All @@ -423,7 +455,7 @@ export async function getPublicFormById(
entityType: IntakeEntityType;
schema: FormSchema;
submitButtonText: string;
designSettings?: Record<string, unknown> | null;
designSettings?: FormDesignSettings | null;
};
previousData?: Record<string, unknown>;
previousSubmitterName?: string;
Expand All @@ -432,7 +464,23 @@ export async function getPublicFormById(
}> {
const queryParams = resubmissionToken ? `?token=${resubmissionToken}` : "";
const response = await apiServices.get(`${BASE_URL}/public/by-id/${publicId}${queryParams}`);
return response.data;
return response.data as {
data: {
form: {
id: number;
name: string;
description: string;
slug: string;
entityType: IntakeEntityType;
schema: FormSchema;
submitButtonText: string;
designSettings?: FormDesignSettings | null;
};
previousData?: Record<string, unknown>;
previousSubmitterName?: string;
previousSubmitterEmail?: string;
};
};
}

// ============================================================================
Expand Down Expand Up @@ -460,5 +508,5 @@ export async function submitPublicFormById(
};
}> {
const response = await apiServices.post(`${BASE_URL}/public/by-id/${publicId}`, data);
return response.data;
return response.data as { data: { submissionId: number; resubmissionToken: string; message: string } };
}
Loading
Loading