mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
Add task metadata and cached queries
Add route-specific metadata for task, client, assignment, and project pages. Centralize task data fetches in React-cached query helpers and reuse them across metadata generation and page rendering.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { ArrowLeft } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import Link from 'next/link';
|
||||
|
||||
import ClientDetailComponent from './ClientDetailComponent';
|
||||
import ClientProfileCard from './ClientProfileCard';
|
||||
import fetchData, { getQueryStringFilteredAssignments } from '@/lib/fetchData';
|
||||
import { getQueryStringFilteredAssignments } from '@/lib/fetchData';
|
||||
import { getFilteredAssignments } from '../../../data';
|
||||
import { getClientById, getAssignmentsByClient } from '../../../queries';
|
||||
import Reveal from '@/components/ui/reveal';
|
||||
|
||||
type Props = {
|
||||
@@ -13,22 +15,60 @@ type Props = {
|
||||
searchParams: Promise<{ [key: string]: string | undefined }>
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { client_id } = await params;
|
||||
|
||||
try {
|
||||
const client = await getClientById(client_id);
|
||||
if (!client) {
|
||||
return {
|
||||
title: 'Client Not Found - HIS Attendance Task System (H.A.T.s)',
|
||||
};
|
||||
}
|
||||
|
||||
const clientName = client.name || 'Client Details';
|
||||
const title = `${clientName} - Task Management - HIS Attendance Task System (H.A.T.s)`;
|
||||
const description = client.description
|
||||
? String(client.description)
|
||||
: `Client profile, project assignments, milestones, and active work orders for ${clientName}.`;
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
openGraph: {
|
||||
title,
|
||||
description,
|
||||
...(client.photo ? { images: [{ url: client.photo, alt: clientName }] } : {}),
|
||||
},
|
||||
twitter: {
|
||||
title,
|
||||
description,
|
||||
...(client.photo ? { images: [client.photo] } : {}),
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
title: 'Client Details - HIS Attendance Task System (H.A.T.s)',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default async function ClientDetailPage({ params, searchParams }: Props) {
|
||||
const { client_id } = await params;
|
||||
|
||||
const searchParams_ = await searchParams;
|
||||
const q = searchParams_!.q
|
||||
const sort = searchParams_!.sort
|
||||
const q = searchParams_?.q;
|
||||
const sort = searchParams_?.sort;
|
||||
|
||||
const query = (q || '').toLowerCase()
|
||||
const query = (q || '').toLowerCase();
|
||||
const sortBy = sort || 'default';
|
||||
|
||||
const queryString = getQueryStringFilteredAssignments(searchParams_)
|
||||
const queryString = await getQueryStringFilteredAssignments(searchParams_ || {});
|
||||
|
||||
const getClientById = fetchData(`/client/${client_id}`)
|
||||
const getAssignmentsByClient = fetchData(queryString ? `/client/project-assignment/${client_id}?${queryString}` : `/client/project-assignment/${client_id}`)
|
||||
const clientPromise = getClientById(client_id);
|
||||
const assignmentsPromise = getAssignmentsByClient(client_id, queryString);
|
||||
|
||||
const [client, assignmentList] = await Promise.all([getClientById, getAssignmentsByClient]);
|
||||
const [client, assignmentList] = await Promise.all([clientPromise, assignmentsPromise]);
|
||||
|
||||
if (!client) {
|
||||
return (
|
||||
@@ -41,7 +81,7 @@ export default async function ClientDetailPage({ params, searchParams }: Props)
|
||||
);
|
||||
}
|
||||
|
||||
const filterAssignments = getFilteredAssignments(assignmentList, query, sortBy)
|
||||
const filterAssignments = getFilteredAssignments(assignmentList, query, sortBy);
|
||||
|
||||
return (
|
||||
<div className="flex-1 space-y-6 p-4 sm:p-8 pt-4 sm:pt-6">
|
||||
@@ -65,4 +105,4 @@ export default async function ClientDetailPage({ params, searchParams }: Props)
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,61 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import Link from 'next/link';
|
||||
import AssignmentDetailComponent from './AssignmentDetailComponent';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { getClientById, getAssignmentById } from '../../../queries';
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ client_id: string; assignment_id: string }>
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { client_id, assignment_id } = await params;
|
||||
|
||||
try {
|
||||
const [client, assignment] = await Promise.all([
|
||||
getClientById(client_id),
|
||||
getAssignmentById(assignment_id),
|
||||
]);
|
||||
|
||||
if (!assignment) {
|
||||
return {
|
||||
title: 'Assignment Not Found - HIS Attendance Task System (H.A.T.s)',
|
||||
};
|
||||
}
|
||||
|
||||
const assignmentName = assignment.wo_name || assignment.im?.im_name || assignment.im_name || assignment.project?.name || `Assignment #${assignment_id}`;
|
||||
const clientName = client?.name || assignment.client?.name || 'Client';
|
||||
const title = `${assignmentName} | ${clientName} - HIS Attendance Task System (H.A.T.s)`;
|
||||
const description = assignment.wo_description || assignment.im?.im_description || `Assignment details, progress tracking, and milestone activity for ${assignmentName} at ${clientName}.`;
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
openGraph: {
|
||||
title,
|
||||
description,
|
||||
},
|
||||
twitter: {
|
||||
title,
|
||||
description,
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
title: 'Assignment Details - HIS Attendance Task System (H.A.T.s)',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default async function AssignmentDetailPage({ params }: Props) {
|
||||
const { client_id, assignment_id } = await params;
|
||||
|
||||
const getClientById = fetchData(`/client/${client_id}`)
|
||||
const getAssignmentById = fetchData(`/project-assignment/${assignment_id}`)
|
||||
const [client, assignment] = await Promise.all([
|
||||
getClientById(client_id),
|
||||
getAssignmentById(assignment_id),
|
||||
]);
|
||||
|
||||
const [client, assignment] = await Promise.all([getClientById, getAssignmentById]);
|
||||
|
||||
// 3. Handle 404 Securely on the server
|
||||
// Handle 404 Securely on the server
|
||||
if (!assignment) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center h-[60vh] space-y-4">
|
||||
@@ -27,8 +67,8 @@ export default async function AssignmentDetailPage({ params }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
// 4. Pass the fetched data to the interactive Client Component
|
||||
// Pass the fetched data to the interactive Client Component
|
||||
return (
|
||||
<AssignmentDetailComponent client={client} initialAssignment={assignment} />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,82 @@
|
||||
import fetchData from "@/lib/fetchData";
|
||||
import ProjectAssignmentForm from "./ProjectAssignmentForm";
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ client_id?: string }>
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||
};
|
||||
|
||||
export default async function CreateAssignmentPage({ params, searchParams }: Props) {
|
||||
const { client_id } = await params;
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const isEdit = resolvedSearchParams?.is_edit;
|
||||
const assignmentId = resolvedSearchParams?.assignment_id;
|
||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||
|
||||
const client = await fetchData(`/client/${client_id}`);
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto p-6 sm:p-8 pt-6 pb-20">
|
||||
<ProjectAssignmentForm
|
||||
client={client}
|
||||
clientId={client_id}
|
||||
isEdit={isEdit ? true : false}
|
||||
assignmentId={assignmentId as any}
|
||||
isPromote={isPromote}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
import type { Metadata } from 'next';
|
||||
import ProjectAssignmentForm from "./ProjectAssignmentForm";
|
||||
import { getClientById, getAssignmentById } from "../../../queries";
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ client_id?: string }>
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params, searchParams }: Props): Promise<Metadata> {
|
||||
const { client_id } = await params;
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const isEdit = resolvedSearchParams?.is_edit === 'true';
|
||||
const assignmentId = typeof resolvedSearchParams?.assignment_id === 'string' ? resolvedSearchParams.assignment_id : undefined;
|
||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||
|
||||
try {
|
||||
const clientPromise = client_id ? getClientById(client_id) : Promise.resolve(undefined);
|
||||
const assignmentPromise = assignmentId && (isEdit || isPromote) ? getAssignmentById(assignmentId) : Promise.resolve(undefined);
|
||||
|
||||
const [client, assignment] = await Promise.all([clientPromise, assignmentPromise]);
|
||||
|
||||
const clientName = client?.name || 'Client';
|
||||
const assignmentName = assignment?.wo_name || assignment?.im?.im_name;
|
||||
|
||||
let title = `New Assignment - ${clientName} - HIS Attendance Task System (H.A.T.s)`;
|
||||
let description = `Create a new project assignment or internal memo for ${clientName}.`;
|
||||
|
||||
if (isPromote) {
|
||||
title = assignmentName
|
||||
? `Promote ${assignmentName} to Work Order - ${clientName} - HIS Attendance Task System (H.A.T.s)`
|
||||
: `Promote Assignment - ${clientName} - HIS Attendance Task System (H.A.T.s)`;
|
||||
description = `Promote internal memo assignment to a formal work order for ${clientName}.`;
|
||||
} else if (isEdit) {
|
||||
title = assignmentName
|
||||
? `Edit ${assignmentName} - ${clientName} - HIS Attendance Task System (H.A.T.s)`
|
||||
: `Edit Assignment - ${clientName} - HIS Attendance Task System (H.A.T.s)`;
|
||||
description = `Update assignment details, timeline, and assigned team members for ${clientName}.`;
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
openGraph: {
|
||||
title,
|
||||
description,
|
||||
...(client?.photo ? { images: [{ url: client.photo, alt: clientName }] } : {}),
|
||||
},
|
||||
twitter: {
|
||||
title,
|
||||
description,
|
||||
...(client?.photo ? { images: [client.photo] } : {}),
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
title: 'Project Assignment - HIS Attendance Task System (H.A.T.s)',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default async function CreateAssignmentPage({ params, searchParams }: Props) {
|
||||
const { client_id } = await params;
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const isEdit = resolvedSearchParams?.is_edit;
|
||||
const assignmentId = resolvedSearchParams?.assignment_id;
|
||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||
|
||||
const client = client_id ? await getClientById(client_id) : undefined;
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto p-6 sm:p-8 pt-6 pb-20">
|
||||
<ProjectAssignmentForm
|
||||
client={client}
|
||||
clientId={client_id}
|
||||
isEdit={isEdit ? true : false}
|
||||
assignmentId={assignmentId as any}
|
||||
isPromote={isPromote}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+56
-8
@@ -1,12 +1,14 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import Link from 'next/link';
|
||||
import fetchData, { getQueryStringFilteredAssignments } from '@/lib/fetchData';
|
||||
import { getQueryStringFilteredAssignments } from '@/lib/fetchData';
|
||||
import { ArrowLeft, Briefcase } from 'lucide-react';
|
||||
import WorkOrderCard from './WorkOrderCard';
|
||||
import ProjectHeader from './ProjectHeader';
|
||||
import DeliveryOverview from './DeliveryOverview';
|
||||
import FilterComponent from '@/app/(dashboard)/task/component/FilterComponent';
|
||||
import { COMPLETE_STATUS_LIST, getFilteredAssignments, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data';
|
||||
import { getClientById, getProjectAssignment } from '../../../../queries';
|
||||
import Reveal from '@/components/ui/reveal';
|
||||
|
||||
type Props = {
|
||||
@@ -14,22 +16,68 @@ type Props = {
|
||||
searchParams: Promise<{ [key: string]: string | undefined }>
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params, searchParams }: Props): Promise<Metadata> {
|
||||
const { client_id, project_id } = await params;
|
||||
const searchParams_ = await searchParams;
|
||||
const queryString = await getQueryStringFilteredAssignments(searchParams_ || {});
|
||||
|
||||
try {
|
||||
const [client, project] = await Promise.all([
|
||||
getClientById(client_id),
|
||||
getProjectAssignment(project_id, queryString),
|
||||
]);
|
||||
|
||||
if (!project) {
|
||||
return {
|
||||
title: 'Project Not Found - HIS Attendance Task System (H.A.T.s)',
|
||||
};
|
||||
}
|
||||
|
||||
const projectName = project.name || `Project #${project_id}`;
|
||||
const clientName = client?.name || project.client?.name || 'Client';
|
||||
const title = `${projectName} | ${clientName} - HIS Attendance Task System (H.A.T.s)`;
|
||||
const description = project.description
|
||||
? String(project.description)
|
||||
: `Delivery overview, work orders, milestones, and team members for ${projectName} at ${clientName}.`;
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
openGraph: {
|
||||
title,
|
||||
description,
|
||||
...(client?.photo ? { images: [{ url: client.photo, alt: clientName }] } : {}),
|
||||
},
|
||||
twitter: {
|
||||
title,
|
||||
description,
|
||||
...(client?.photo ? { images: [client.photo] } : {}),
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
title: 'Project Details - HIS Attendance Task System (H.A.T.s)',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default async function ProjectDetailPage({ params, searchParams }: Props) {
|
||||
const { client_id, project_id } = await params;
|
||||
const searchParams_ = await searchParams;
|
||||
|
||||
const q = searchParams_!.q
|
||||
const sort = searchParams_!.sort
|
||||
const q = searchParams_?.q;
|
||||
const sort = searchParams_?.sort;
|
||||
|
||||
const query = (q || '').toLowerCase()
|
||||
const query = (q || '').toLowerCase();
|
||||
const sortBy = sort || 'default';
|
||||
|
||||
const queryString = getQueryStringFilteredAssignments(searchParams_)
|
||||
const queryString = await getQueryStringFilteredAssignments(searchParams_ || {});
|
||||
|
||||
const getClientById = fetchData(`/client/${client_id}`)
|
||||
const getAssignmentByProjectId = fetchData(queryString ? `/project/project-assignment/${project_id}?${queryString}` : `/project/project-assignment/${project_id}`)
|
||||
const clientPromise = getClientById(client_id);
|
||||
const projectPromise = getProjectAssignment(project_id, queryString);
|
||||
|
||||
const [client, project] = await Promise.all([clientPromise, projectPromise]);
|
||||
|
||||
const [client, project] = await Promise.all([getClientById, getAssignmentByProjectId]);
|
||||
|
||||
if (!project) {
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { lazy, Suspense } from 'react';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import type { Metadata } from 'next';
|
||||
import { getFilteredClients } from './data';
|
||||
import { getClients } from './queries';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
|
||||
const HomeTask = lazy(() => import('./component/HomeTask'));
|
||||
@@ -10,6 +11,34 @@ type Props = {
|
||||
searchParams: Promise<{ view?: string; q?: string; status?: string; sort?: string; layout?: string }>
|
||||
};
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
try {
|
||||
const allClients = await getClients();
|
||||
const clientCount = Array.isArray(allClients) ? allClients.length : 0;
|
||||
const description = clientCount > 0
|
||||
? `Manage ${clientCount} clients, project assignments, work orders, internal memos, and team task assignments.`
|
||||
: 'Manage client project assignments, work orders, internal memos, and team task assignments.';
|
||||
|
||||
return {
|
||||
title: 'Task Management (Client Overview) - HIS Attendance Task System (H.A.T.s)',
|
||||
description,
|
||||
openGraph: {
|
||||
title: 'Task Management (Client Overview) - HIS Attendance Task System (H.A.T.s)',
|
||||
description,
|
||||
},
|
||||
twitter: {
|
||||
title: 'Task Management (Client Overview) - HIS Attendance Task System (H.A.T.s)',
|
||||
description,
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
title: 'Task Management - HIS Attendance Task System (H.A.T.s)',
|
||||
description: 'Manage client project assignments, work orders, internal memos, and team task assignments.',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default async function ClientsPage({ searchParams }: Props) {
|
||||
const searchParams_ = await searchParams;
|
||||
|
||||
@@ -21,7 +50,7 @@ export default async function ClientsPage({ searchParams }: Props) {
|
||||
|
||||
// const queryString = getQueryStringFilteredAssignments(searchParams_)
|
||||
|
||||
const allClients = await fetchData('/client')
|
||||
const allClients = await getClients();
|
||||
// const getAssignment = fetchData(queryString ? `/project-assignment?${queryString}` : '/project-assignment')
|
||||
|
||||
// const [allClients, allAssignments] = await Promise.all([getClient, getAssignment]);
|
||||
@@ -48,4 +77,4 @@ export default async function ClientsPage({ searchParams }: Props) {
|
||||
</Suspense> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,69 @@
|
||||
import ProjectAssignmentForm from "../client-detail/[client_id]/project-assignments/ProjectAssignmentForm";
|
||||
|
||||
type Props = {
|
||||
searchParams: Promise<{ is_edit?: string; assignment_id?: string; promote?: string; is_promote?: string }>
|
||||
};
|
||||
|
||||
export default async function CreateAssignmentPage({ searchParams }: Props) {
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const isEdit = resolvedSearchParams?.is_edit;
|
||||
const assignmentId = resolvedSearchParams?.assignment_id;
|
||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto p-6 sm:p-8 pt-6 pb-20">
|
||||
<ProjectAssignmentForm
|
||||
isEdit={isEdit === 'true' ? true : false}
|
||||
assignmentId={assignmentId as any}
|
||||
isPromote={isPromote}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
import type { Metadata } from 'next';
|
||||
import ProjectAssignmentForm from "../client-detail/[client_id]/project-assignments/ProjectAssignmentForm";
|
||||
import { getAssignmentById } from "../queries";
|
||||
|
||||
type Props = {
|
||||
searchParams: Promise<{ is_edit?: string; assignment_id?: string; promote?: string; is_promote?: string }>
|
||||
};
|
||||
|
||||
export async function generateMetadata({ searchParams }: Props): Promise<Metadata> {
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const isEdit = resolvedSearchParams?.is_edit === 'true';
|
||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||
const assignmentId = resolvedSearchParams?.assignment_id;
|
||||
|
||||
let assignmentName: string | undefined;
|
||||
if (assignmentId && (isEdit || isPromote)) {
|
||||
try {
|
||||
const assignment = await getAssignmentById(assignmentId);
|
||||
assignmentName = assignment?.wo_name || assignment?.im?.im_name || assignment?.project?.name;
|
||||
} catch {
|
||||
// fallback gracefully
|
||||
}
|
||||
}
|
||||
|
||||
let title = 'Create Project Assignment - HIS Attendance Task System (H.A.T.s)';
|
||||
let description = 'Create a new project assignment, work order, or internal memo.';
|
||||
|
||||
if (isPromote) {
|
||||
title = assignmentName
|
||||
? `Promote ${assignmentName} to Work Order - HIS Attendance Task System (H.A.T.s)`
|
||||
: 'Promote Assignment to Work Order - HIS Attendance Task System (H.A.T.s)';
|
||||
description = 'Promote an existing internal memo assignment to a formal work order.';
|
||||
} else if (isEdit) {
|
||||
title = assignmentName
|
||||
? `Edit ${assignmentName} - HIS Attendance Task System (H.A.T.s)`
|
||||
: 'Edit Project Assignment - HIS Attendance Task System (H.A.T.s)';
|
||||
description = 'Update details, milestones, and assigned team members for this assignment.';
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
openGraph: {
|
||||
title,
|
||||
description,
|
||||
},
|
||||
twitter: {
|
||||
title,
|
||||
description,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function CreateAssignmentPage({ searchParams }: Props) {
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const isEdit = resolvedSearchParams?.is_edit;
|
||||
const assignmentId = resolvedSearchParams?.assignment_id;
|
||||
const isPromote = resolvedSearchParams?.promote === 'true' || resolvedSearchParams?.is_promote === 'true';
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto p-6 sm:p-8 pt-6 pb-20">
|
||||
<ProjectAssignmentForm
|
||||
isEdit={isEdit === 'true' ? true : false}
|
||||
assignmentId={assignmentId as any}
|
||||
isPromote={isPromote}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { cache } from 'react';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { IClient } from './types';
|
||||
import { IProjectAssignment } from './type.assignment';
|
||||
import { IProject } from './type.project';
|
||||
|
||||
/**
|
||||
* Server-side memoized data fetchers for /task and child routes.
|
||||
* Uses React cache() to deduplicate identical data requests across generateMetadata and Page components.
|
||||
* @see https://nextjs.org/docs/app/getting-started/metadata-and-og-images#memoizing-data-requests
|
||||
*/
|
||||
|
||||
export const getClients = cache(async (): Promise<IClient[]> => {
|
||||
return await fetchData('/client');
|
||||
});
|
||||
|
||||
export const getClientById = cache(async (clientId: string): Promise<IClient> => {
|
||||
return await fetchData(`/client/${clientId}`);
|
||||
});
|
||||
|
||||
export const getAssignmentsByClient = cache(async (clientId: string, queryString?: string): Promise<IProjectAssignment[]> => {
|
||||
const url = queryString ? `/client/project-assignment/${clientId}?${queryString}` : `/client/project-assignment/${clientId}`;
|
||||
return await fetchData(url);
|
||||
});
|
||||
|
||||
export const getAssignmentById = cache(async (assignmentId: string): Promise<IProjectAssignment> => {
|
||||
return await fetchData(`/project-assignment/${assignmentId}`);
|
||||
});
|
||||
|
||||
export const getProjectAssignment = cache(async (projectId: string, queryString?: string): Promise<IProject> => {
|
||||
const url = queryString ? `/project/project-assignment/${projectId}?${queryString}` : `/project/project-assignment/${projectId}`;
|
||||
return await fetchData(url);
|
||||
});
|
||||
Reference in New Issue
Block a user