mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
de8d463b97
Relocate the task query module and update its type and route imports to use the new `utils/queries` path.
70 lines
2.7 KiB
TypeScript
70 lines
2.7 KiB
TypeScript
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>
|
|
);
|
|
}
|