fix: form create task-ta

This commit is contained in:
Sabda Yagra 2026-01-12 09:09:52 +07:00
parent ec2d7eb203
commit 7c721dcc96
2 changed files with 143 additions and 94 deletions

View File

@ -43,7 +43,7 @@ import { getCsrfToken } from "@/service/auth";
import { loading } from "@/lib/swal"; import { loading } from "@/lib/swal";
import { useTranslations } from "next-intl"; import { useTranslations } from "next-intl";
import dynamic from "next/dynamic"; import dynamic from "next/dynamic";
import { cn } from "@/lib/utils"; import { cn, getCookiesDecrypt } from "@/lib/utils";
import { import {
Popover, Popover,
PopoverContent, PopoverContent,
@ -181,6 +181,32 @@ export default function FormTaskTa() {
mode: "all", mode: "all",
}); });
const [profile, setProfile] = useState<any>(null);
const userLevelId = Number(getCookiesDecrypt("ulie"));
const roleId = Number(getCookiesDecrypt("urie"));
const userId = Number(getCookiesDecrypt("uie"));
const MABES_LEVEL_ID = 216;
const APPROVER_ROLE_ID = 3;
const isMabes = userLevelId === MABES_LEVEL_ID;
const isApprover = roleId === APPROVER_ROLE_ID;
const isMabesApprover =
userLevelId === MABES_LEVEL_ID && roleId === APPROVER_ROLE_ID;
useEffect(() => {
async function fetchUserLevel() {
try {
const res = await getUserLevelForAssignments();
setProfile(res?.data?.data);
} catch (e) {
console.error("Failed fetch user level", e);
}
}
fetchUserLevel();
}, []);
useEffect(() => { useEffect(() => {
getDataAdditional(); getDataAdditional();
}, []); }, []);
@ -360,12 +386,20 @@ export default function FormTaskTa() {
const requestData = { const requestData = {
...data, ...data,
assignedToUsers: handleExpertChange(), assignedToUsers: handleExpertChange(),
// assignedToUsers: isMabesApprover ? "464" : handleExpertChange(),
assignmentType: taskType, assignmentType: taskType,
assignmentTypeId: type, assignmentTypeId: type,
expertCompetencies: Array.from(selectedCompetencies).join(","), expertCompetencies: Array.from(selectedCompetencies).join(","),
attachmentUrl: cleanedLinks, attachmentUrl: cleanedLinks,
}; };
console.log("FINAL ASSIGNED TO:", {
isMabesApprover,
assignedToUsers: isMabesApprover
? String(roleId)
: handleExpertChange(),
});
const response = await createTaskTa(requestData); const response = await createTaskTa(requestData);
const id = String(response?.data?.data.id); const id = String(response?.data?.data.id);
@ -718,6 +752,7 @@ export default function FormTaskTa() {
</PopoverContent> </PopoverContent>
</Popover> </Popover>
</div> </div>
{!isMabesApprover && (
<div className="mt-5 space-y-2"> <div className="mt-5 space-y-2">
<Label> <Label>
{t("areas-expertise", { defaultValue: "Areas Expertise" })} {t("areas-expertise", { defaultValue: "Areas Expertise" })}
@ -735,6 +770,8 @@ export default function FormTaskTa() {
))} ))}
</div> </div>
</div> </div>
)}
{!isMabesApprover && (
<div className="mt-5 space-y-2"> <div className="mt-5 space-y-2">
<Label> <Label>
{t("choose-expert", { defaultValue: "Choose Expert" })} {t("choose-expert", { defaultValue: "Choose Expert" })}
@ -762,8 +799,12 @@ export default function FormTaskTa() {
className="mr-3" className="mr-3"
/> />
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<div className="font-bold">{expert.fullname}</div> <div className="font-bold">
<div className="italic">({expert.username})</div> {expert.fullname}
</div>
<div className="italic">
({expert.username})
</div>
</div> </div>
</Label> </Label>
</div> </div>
@ -813,6 +854,7 @@ export default function FormTaskTa() {
</div> </div>
)} )}
</div> </div>
)}
<div className="mt-5 space-y-2"> <div className="mt-5 space-y-2">
<Label>{t("description", { defaultValue: "Description" })}</Label> <Label>{t("description", { defaultValue: "Description" })}</Label>
<Controller <Controller

View File

@ -168,6 +168,13 @@ export function getMenuList(pathname: string, t: any): Group[] {
icon: "heroicons:shopping-cart", icon: "heroicons:shopping-cart",
children: [], children: [],
}, },
{
href: "/contributor/task-ta",
label: "penugasan TA",
active: pathname.includes("/contributor/task-ta"),
icon: "heroicons:shopping-cart",
children: [],
},
], ],
}, },
], ],