Tighten task actions and image uploads

Gate assignment and team actions by permissions, limit client and end-user images to 2 MB, and make the technical status end date optional. Also update status remark handling and rename the Task navigation label.
This commit is contained in:
Ichsan Kurniawan
2026-11-18 18:19:38 +07:00
parent faa22e93e0
commit d4168b45f2
9 changed files with 47 additions and 34 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ export function MainNav({ className, ...props }: HTMLAttributes<HTMLElement>) {
className={`text-sm font-medium transition-colors hover:text-his hover:border-b-[3px] border-his pt-6 pb-5 ${getMenuActiveStyle('/task')}`}
>
<i className="ti ti-checklist text-base mr-0.5"></i>
My Task
Task
</Link>
{session?.user.detail.role.allow_admin_panel &&
<Link
@@ -10,6 +10,7 @@ import { useRouter, useSearchParams } from 'next/navigation';
import dynamic from 'next/dynamic';
import FilterComponent from '../../../component/FilterComponent';
import ProjectAssignmentDashboardStats from '../../../component/project-assignment/ProjectAssignmentDashboardStats';
import { IClient } from '../../../types';
const AssignmentList = dynamic(
() => import('../../../component/project-assignment/AssignmentList'),
@@ -69,12 +70,13 @@ const ConfirmDeleteWithInput = dynamic(
);
interface Props {
client: IClient;
clientId: string;
assignmentLists: IProjectAssignment[];
actions?: string[]
}
export default function ClientDetailComponent({ clientId, assignmentLists, actions }: Props) {
export default function ClientDetailComponent({ client, clientId, assignmentLists, actions }: Props) {
const router = useRouter();
const searchParams = useSearchParams();
const urlLayout = searchParams?.get('layout') as 'grid' | 'list' | null;
@@ -133,7 +135,7 @@ export default function ClientDetailComponent({ clientId, assignmentLists, actio
This client doesn't have any projects or internal memos yet. Try to change the filter or create one to get started.
</p>
</div>
{actions?.includes("CREATE_ASSIGNMENT") &&
{client?.name && actions?.includes("CREATE_ASSIGNMENT") &&
<Link href={`/task/client-detail/${clientId}/project-assignments`}>
<Button variant="outline" className="mt-4">Create Assignment</Button>
</Link>
@@ -61,7 +61,7 @@ export default function ClientProfileCard({ client, clientId, actions }: Props)
{/* Right: + New assignment Button */}
<div className="shrink-0 self-start lg:self-center">
{actions?.includes("CREATE_ASSIGNMENT") &&
{client.name && actions?.includes("CREATE_ASSIGNMENT") &&
<Link href={`/task/client-detail/${clientId}/project-assignments`}>
<Button className="gap-2 bg-his hover:bg-his/90 text-white font-medium rounded-xl px-5 py-2.5 shadow-sm transition-transform active:scale-[0.98]">
<Plus className="h-4 w-4" />
@@ -103,6 +103,7 @@ export default async function ClientDetailPage({ params, searchParams }: Props)
</Reveal>
<ClientDetailComponent
client={client}
clientId={client_id}
assignmentLists={filterAssignments}
actions={actions}
@@ -527,15 +527,17 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
</button>
</div>
) : null}
<Button
onClick={() => setAction('MANAGE_EMPLOYEE')}
variant="outline"
size="sm"
className="gap-1.5 transition-transform active:scale-[0.98]"
>
<UserPlus className="h-4 w-4" />
Manage team
</Button>
{actions?.includes("MANAGE_TEAM") &&
<Button
onClick={() => setAction('MANAGE_EMPLOYEE')}
variant="outline"
size="sm"
className="gap-1.5 transition-transform active:scale-[0.98]"
>
<UserPlus className="h-4 w-4" />
Manage team
</Button>
}
</div>
}
>
+11 -3
View File
@@ -36,7 +36,8 @@ const FormEndUser: FC<Props> = ({ data, onSuccess, onCancel }) => {
const existFile = data?.photo || null
const dropzoneRef = useRef<any>(null);
const maxSizeMB = 5
const maxSizeMB = 2
const maxSizeBytes = maxSizeMB * 1024 * 1024;
const openDialog = () => {
// Note that the ref is set async,
@@ -48,6 +49,13 @@ const FormEndUser: FC<Props> = ({ data, onSuccess, onCancel }) => {
const onDrop = useCallback((acceptedFiles: any[]) => {
acceptedFiles.forEach(async (file: any) => {
if (file.size > maxSizeBytes) {
toast.error('File size exceeds the limit', {
description: `Maximum allowed file size is ${maxSizeMB}MB.`,
});
return;
}
const reader = new FileReader();
reader.onabort = () => console.log('file reading was aborted');
@@ -184,7 +192,7 @@ const FormEndUser: FC<Props> = ({ data, onSuccess, onCancel }) => {
<Label>Add End User Image</Label>
{/* Drop area */}
<Dropzone ref={dropzoneRef} onDrop={onDrop} multiple={false} noClick noKeyboard
accept={{ 'image/*': ['.png', '.bmp', '.jpeg', '.jpg', '.webp'] }}
accept={{ 'image/*': ['.svg', '.png', '.bmp', '.jpeg', '.jpg', '.webp'] }}
>
{/* @ts-ignore */}
{({ getRootProps, getInputProps, acceptedFiles }) => {
@@ -217,7 +225,7 @@ const FormEndUser: FC<Props> = ({ data, onSuccess, onCancel }) => {
</div>
<p className="mb-1.5 text-sm font-medium">Drop your files here</p>
<p className="text-muted-foreground text-xs">
SVG, PNG, JPG or GIF (max. {maxSizeMB}MB)
SVG, PNG, JPG, WEBP, BMP or GIF (max. {maxSizeMB}MB)
</p>
<Button type='button' variant="outline" className="mt-4" onClick={openDialog}>
<UploadIcon className="-ms-1 opacity-60" aria-hidden="true" />
@@ -76,7 +76,7 @@ export default function UpdateAdministrationStatus({
}, [assignment, statusList]);
const [selectedStatusId, setSelectedStatusId] = useState<string>(initialStatusId);
const [description, setDescription] = useState<string>(assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || '');
const [description, setDescription] = useState<string>(assignment?.project_assignment_status?.remark || assignment?.note || '');
useEffect(() => {
if (initialStatusId) {
@@ -85,7 +85,7 @@ export default function UpdateAdministrationStatus({
}, [initialStatusId]);
useEffect(() => {
const initialRemark = assignment?.project_assignment_status_notes || assignment?.project_assignment_status?.remark || assignment?.project_assignment_status?.description || assignment?.note || '';
const initialRemark = assignment?.project_assignment_status_notes || assignment?.project_assignment_status?.remark || assignment?.note || '';
setDescription(initialRemark);
}, [assignment]);
@@ -137,11 +137,11 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
return dayjs(endDate).isBefore(dayjs(startDate), 'day');
}, [startDate, endDate]);
const isDateMissing = !startDate || !endDate;
const isDateMissing = !startDate;
const handleSave = async () => {
if (isDateMissing) {
toast.error('Date range required', {
toast.error('Start Date is required', {
description: 'Please select both a start date and an end date.'
});
return;
@@ -258,7 +258,7 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
</div>
<div className="space-y-1.5">
<label className="text-xs font-medium text-foreground">
End Date <span className="text-destructive">*</span>
End Date
</label>
<DatePicker
date={endDate}
@@ -298,18 +298,10 @@ function EditTechnicalStatusModal({ assignmentId, data, onClose, onSuccess }: Ed
</div>
<DialogFooter className="gap-2">
<Button
type="button"
variant="outline"
onClick={onClose}
disabled={isSaving}
>
<Button type="button" variant="outline" onClick={onClose} disabled={isSaving}>
Cancel
</Button>
<Button
type="button"
onClick={handleSave}
disabled={isSaving || isDateRangeInvalid || isDateMissing}
<Button type="button" onClick={handleSave} disabled={isSaving || isDateRangeInvalid || isDateMissing}
className="bg-his text-white hover:bg-his/90 gap-1.5 shadow-2xs font-medium"
>
{isSaving ? (
@@ -40,7 +40,8 @@ const FormClient: FC<Props> = ({ data, onSuccess, onCancel, isRedirectToDetail }
const existFile = data?.photo || null
const dropzoneRef = useRef<any>(null);
const maxSizeMB = 5
const maxSizeMB = 2
const maxSizeBytes = maxSizeMB * 1024 * 1024;
const openDialog = () => {
if (dropzoneRef.current) {
@@ -50,6 +51,13 @@ const FormClient: FC<Props> = ({ data, onSuccess, onCancel, isRedirectToDetail }
const onDrop = useCallback((acceptedFiles: any[]) => {
acceptedFiles.forEach(async (file: any) => {
if (file.size > maxSizeBytes) {
toast.error('File size exceeds the limit', {
description: `Maximum allowed file size is ${maxSizeMB}MB.`,
});
return;
}
const reader = new FileReader();
reader.onabort = () => console.log('file reading was aborted');
@@ -208,7 +216,7 @@ const FormClient: FC<Props> = ({ data, onSuccess, onCancel, isRedirectToDetail }
<Label>Add Client Image</Label>
{/* Drop area */}
<Dropzone ref={dropzoneRef} onDrop={onDrop} multiple={false} noClick noKeyboard
accept={{ 'image/*': ['.png', '.bmp', '.jpeg', '.jpg', '.webp'] }}
accept={{ 'image/*': ['.svg', '.png', '.bmp', '.jpeg', '.jpg', '.webp'] }}
>
{/* @ts-ignore */}
{({ getRootProps, getInputProps, acceptedFiles }) => {
@@ -241,7 +249,7 @@ const FormClient: FC<Props> = ({ data, onSuccess, onCancel, isRedirectToDetail }
</div>
<p className="mb-1.5 text-sm font-medium">Drop your files here</p>
<p className="text-muted-foreground text-xs">
SVG, PNG, JPG or GIF (max. {maxSizeMB}MB)
SVG, PNG, JPG, WEBP, BMP or GIF (max. {maxSizeMB}MB)
</p>
<Button type='button' variant="outline" className="mt-4" onClick={openDialog}>
<UploadIcon className="-ms-1 opacity-60" aria-hidden="true" />