mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
Move task queries into utils
Relocate the task query module and update its type and route imports to use the new `utils/queries` path.
This commit is contained in:
@@ -7,7 +7,7 @@ import ClientDetailComponent from './ClientDetailComponent';
|
||||
import ClientProfileCard from './ClientProfileCard';
|
||||
import { getQueryStringFilteredAssignments } from '@/lib/fetchData';
|
||||
import { getFilteredAssignments } from '../../../data';
|
||||
import { getClientById, getAssignmentsByClient } from '../../../queries';
|
||||
import { getClientById, getAssignmentsByClient } from '../../../utils/queries';
|
||||
import Reveal from '@/components/ui/reveal';
|
||||
|
||||
type Props = {
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Metadata } from 'next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import Link from 'next/link';
|
||||
import AssignmentDetailComponent from './AssignmentDetailComponent';
|
||||
import { getClientById, getAssignmentById } from '../../../queries';
|
||||
import { getClientById, getAssignmentById } from '../../../utils/queries';
|
||||
|
||||
type Props = {
|
||||
params: Promise<{ client_id: string; assignment_id: string }>
|
||||
@@ -12,10 +12,7 @@ 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),
|
||||
]);
|
||||
const [client, assignment] = await Promise.all([getClientById(client_id), getAssignmentById(assignment_id)]);
|
||||
|
||||
if (!assignment) {
|
||||
return {
|
||||
@@ -50,10 +47,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
export default async function AssignmentDetailPage({ params }: Props) {
|
||||
const { client_id, assignment_id } = await params;
|
||||
|
||||
const [client, assignment] = await Promise.all([
|
||||
getClientById(client_id),
|
||||
getAssignmentById(assignment_id),
|
||||
]);
|
||||
const [client, assignment] = await Promise.all([getClientById(client_id), getAssignmentById(assignment_id)]);
|
||||
|
||||
// Handle 404 Securely on the server
|
||||
if (!assignment) {
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
import type { Metadata } from 'next';
|
||||
import ProjectAssignmentForm from "./ProjectAssignmentForm";
|
||||
import { getClientById, getAssignmentById } from "../../../utils/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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ 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 { getClientById, getProjectAssignment } from '../../../../utils/queries';
|
||||
import Reveal from '@/components/ui/reveal';
|
||||
|
||||
type Props = {
|
||||
@@ -22,10 +22,7 @@ export async function generateMetadata({ params, searchParams }: Props): Promise
|
||||
const queryString = await getQueryStringFilteredAssignments(searchParams_ || {});
|
||||
|
||||
try {
|
||||
const [client, project] = await Promise.all([
|
||||
getClientById(client_id),
|
||||
getProjectAssignment(project_id, queryString),
|
||||
]);
|
||||
const [client, project] = await Promise.all([getClientById(client_id), getProjectAssignment(project_id, queryString),]);
|
||||
|
||||
if (!project) {
|
||||
return {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { lazy, Suspense } from 'react';
|
||||
import type { Metadata } from 'next';
|
||||
import { getFilteredClients } from './data';
|
||||
import { getClients } from './queries';
|
||||
import { getClients } from './utils/queries';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
|
||||
const HomeTask = lazy(() => import('./component/HomeTask'));
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
import type { Metadata } from 'next';
|
||||
import ProjectAssignmentForm from "../client-detail/[client_id]/project-assignments/ProjectAssignmentForm";
|
||||
import { getAssignmentById } from "../utils/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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { cache } from 'react';
|
||||
import fetchData from '@/lib/fetchData';
|
||||
import { IClient } from './types';
|
||||
import { IProjectAssignment } from './type.assignment';
|
||||
import { IProject } from './type.project';
|
||||
import { IClient } from '../types';
|
||||
import { IProjectAssignment } from '../type.assignment';
|
||||
import { IProject } from '../type.project';
|
||||
|
||||
/**
|
||||
* Server-side memoized data fetchers for /task and child routes.
|
||||
Reference in New Issue
Block a user