Merge branch 'dev-sabda-v2' of https://gitlab.com/hanifsalafi/mediahub_redesign
This commit is contained in:
commit
933a672280
|
|
@ -22,7 +22,7 @@ import withReactContent from "sweetalert2-react-content";
|
|||
import Swal from "sweetalert2";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
const useTableColumns = (activeTab: "ta" | "daily" | "special") => {
|
||||
const useTableColumns = (activeTab: "ta" | "daily" | "special" |"mabes-koor") => {
|
||||
const t = useTranslations("Table");
|
||||
const columns: ColumnDef<any>[] = [
|
||||
{
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -43,7 +43,7 @@ import { getCsrfToken } from "@/service/auth";
|
|||
import { loading } from "@/lib/swal";
|
||||
import { useTranslations } from "next-intl";
|
||||
import dynamic from "next/dynamic";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { cn, getCookiesDecrypt } from "@/lib/utils";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
|
|
@ -181,6 +181,33 @@ export default function FormTaskTa() {
|
|||
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; // userLevelId Mabes Polri
|
||||
const APPROVER_ROLE_ID = 3; // roleId Approver
|
||||
const isMabes = userLevelId === MABES_LEVEL_ID;
|
||||
const isApprover = roleId === APPROVER_ROLE_ID;
|
||||
|
||||
const isMabesApprover =
|
||||
userLevelId === MABES_LEVEL_ID && roleId === APPROVER_ROLE_ID;
|
||||
|
||||
const shouldHideExpert = isMabes && isApprover;
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchUserLevel() {
|
||||
try {
|
||||
const res = await getUserLevelForAssignments();
|
||||
setProfile(res?.data?.data);
|
||||
} catch (e) {
|
||||
console.error("Failed fetch user level", e);
|
||||
}
|
||||
}
|
||||
fetchUserLevel();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
getDataAdditional();
|
||||
}, []);
|
||||
|
|
@ -352,14 +379,79 @@ export default function FormTaskTa() {
|
|||
// // });
|
||||
// };
|
||||
|
||||
// const save = async (data: TaskSchema) => {
|
||||
// const cleanedLinks = links
|
||||
// .map((link) => link.trim())
|
||||
// .filter((link) => link.startsWith("http"));
|
||||
|
||||
// const requestData = {
|
||||
// ...data,
|
||||
// // assignedToUsers: handleExpertChange(),
|
||||
// assignedToUsers: isMabesApprover ? "464" : handleExpertChange(),
|
||||
// assignmentType: taskType,
|
||||
// assignmentTypeId: type,
|
||||
// expertCompetencies: Array.from(selectedCompetencies).join(","),
|
||||
// attachmentUrl: cleanedLinks,
|
||||
// };
|
||||
|
||||
// console.log("FINAL ASSIGNED TO:", {
|
||||
// isMabesApprover,
|
||||
// assignedToUsers: isMabesApprover
|
||||
// ? String(roleId)
|
||||
// : handleExpertChange(),
|
||||
// });
|
||||
|
||||
// const response = await createTaskTa(requestData);
|
||||
// const id = String(response?.data?.data.id);
|
||||
|
||||
// // Set block table TA
|
||||
// localStorage.setItem("TA_UPLOAD_IN_PROGRESS", "true");
|
||||
|
||||
// loading(); // SHOW SWAL LOADING
|
||||
|
||||
// // Kumpulkan semua upload
|
||||
// const allUploads: Promise<any>[] = [];
|
||||
|
||||
// imageFiles.forEach((item, idx) =>
|
||||
// allUploads.push(uploadResumableFile(idx, id, item, "1", "0"))
|
||||
// );
|
||||
|
||||
// videoFiles.forEach((item, idx) =>
|
||||
// allUploads.push(uploadResumableFile(idx, id, item, "2", "0"))
|
||||
// );
|
||||
|
||||
// textFiles.forEach((item, idx) =>
|
||||
// allUploads.push(uploadResumableFile(idx, id, item, "3", "0"))
|
||||
// );
|
||||
|
||||
// audioFiles.forEach((item, idx) =>
|
||||
// allUploads.push(uploadResumableFile(idx, id, item, "4", "0"))
|
||||
// );
|
||||
|
||||
// // Tunggu upload selesai
|
||||
// await Promise.all(allUploads);
|
||||
|
||||
// // Hapus flag
|
||||
// localStorage.removeItem("TA_UPLOAD_IN_PROGRESS");
|
||||
|
||||
// // Close loading + redirect
|
||||
// successSubmit("/in/contributor/task-ta");
|
||||
// };
|
||||
|
||||
const save = async (data: TaskSchema) => {
|
||||
try {
|
||||
loading();
|
||||
|
||||
const cleanedLinks = links
|
||||
.map((link) => link.trim())
|
||||
.filter((link) => link.startsWith("http"));
|
||||
|
||||
const requestData = {
|
||||
...data,
|
||||
assignedToUsers: handleExpertChange(),
|
||||
// assignedToUsers: isMabesApprover ? "464" : handleExpertChange(),
|
||||
assignedToUsers: isMabesApprover
|
||||
? ["464", "8258"]
|
||||
: handleExpertChange(),
|
||||
assignmentType: taskType,
|
||||
assignmentTypeId: type,
|
||||
expertCompetencies: Array.from(selectedCompetencies).join(","),
|
||||
|
|
@ -367,40 +459,46 @@ export default function FormTaskTa() {
|
|||
};
|
||||
|
||||
const response = await createTaskTa(requestData);
|
||||
const id = String(response?.data?.data.id);
|
||||
|
||||
// Set block table TA
|
||||
localStorage.setItem("TA_UPLOAD_IN_PROGRESS", "true");
|
||||
if (!response?.data?.data?.id) {
|
||||
throw new Error("Gagal membuat task");
|
||||
}
|
||||
|
||||
loading(); // SHOW SWAL LOADING
|
||||
const assignmentId = String(response.data.data.id);
|
||||
|
||||
// Kumpulkan semua upload
|
||||
const allUploads: Promise<any>[] = [];
|
||||
const uploads: Promise<any>[] = [];
|
||||
|
||||
imageFiles.forEach((item, idx) =>
|
||||
allUploads.push(uploadResumableFile(idx, id, item, "1", "0"))
|
||||
imageFiles.forEach((file, i) =>
|
||||
uploads.push(uploadResumableFile(i, assignmentId, file, "1", "0"))
|
||||
);
|
||||
|
||||
videoFiles.forEach((item, idx) =>
|
||||
allUploads.push(uploadResumableFile(idx, id, item, "2", "0"))
|
||||
videoFiles.forEach((file, i) =>
|
||||
uploads.push(uploadResumableFile(i, assignmentId, file, "2", "0"))
|
||||
);
|
||||
|
||||
textFiles.forEach((item, idx) =>
|
||||
allUploads.push(uploadResumableFile(idx, id, item, "3", "0"))
|
||||
textFiles.forEach((file, i) =>
|
||||
uploads.push(uploadResumableFile(i, assignmentId, file, "3", "0"))
|
||||
);
|
||||
|
||||
audioFiles.forEach((item, idx) =>
|
||||
allUploads.push(uploadResumableFile(idx, id, item, "4", "0"))
|
||||
audioFiles.forEach((file, i) =>
|
||||
uploads.push(uploadResumableFile(i, assignmentId, file, "4", "0"))
|
||||
);
|
||||
|
||||
// Tunggu upload selesai
|
||||
await Promise.all(allUploads);
|
||||
await Promise.all(uploads);
|
||||
|
||||
// Hapus flag
|
||||
localStorage.removeItem("TA_UPLOAD_IN_PROGRESS");
|
||||
|
||||
// Close loading + redirect
|
||||
successSubmit("/in/contributor/task-ta");
|
||||
} catch (err: any) {
|
||||
console.error("SUBMIT ERROR:", err);
|
||||
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Gagal",
|
||||
text:
|
||||
err?.response?.data?.message ||
|
||||
err?.message ||
|
||||
"Terjadi kesalahan, data tidak tersimpan",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const onSubmit = (data: TaskSchema) => {
|
||||
|
|
@ -543,21 +641,65 @@ export default function FormTaskTa() {
|
|||
|
||||
// upload.start();
|
||||
// }
|
||||
// function uploadResumableFile(
|
||||
// idx: number,
|
||||
// id: string,
|
||||
// file: any,
|
||||
// fileTypeId: string,
|
||||
// duration: string
|
||||
// ) {
|
||||
// return new Promise(async (resolve, reject) => {
|
||||
// const resCsrf = await getCsrfToken();
|
||||
// const csrfToken = resCsrf?.data?.token;
|
||||
|
||||
// const upload = new Upload(file, {
|
||||
// endpoint: `${process.env.NEXT_PUBLIC_API}/assignment-expert/file/upload`,
|
||||
// headers: { "X-XSRF-TOKEN": csrfToken },
|
||||
// retryDelays: [0, 3000, 6000, 12000],
|
||||
// chunkSize: 20000,
|
||||
// metadata: {
|
||||
// assignmentId: id,
|
||||
// filename: file.name,
|
||||
// contentType: file.type,
|
||||
// fileTypeId,
|
||||
// duration,
|
||||
// },
|
||||
|
||||
// onBeforeRequest(req) {
|
||||
// req.getUnderlyingObject().withCredentials = true;
|
||||
// },
|
||||
|
||||
// onError(err) {
|
||||
// console.error("Upload error:", err);
|
||||
// reject(err);
|
||||
// },
|
||||
|
||||
// onSuccess() {
|
||||
// console.log("Upload selesai:", file.name);
|
||||
// resolve(true);
|
||||
// },
|
||||
// });
|
||||
|
||||
// upload.start();
|
||||
// });
|
||||
// }
|
||||
|
||||
function uploadResumableFile(
|
||||
idx: number,
|
||||
id: string,
|
||||
file: any,
|
||||
file: File,
|
||||
fileTypeId: string,
|
||||
duration: string
|
||||
) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const resCsrf = await getCsrfToken();
|
||||
const csrfToken = resCsrf?.data?.token;
|
||||
|
||||
const upload = new Upload(file, {
|
||||
endpoint: `${process.env.NEXT_PUBLIC_API}/assignment-expert/file/upload`,
|
||||
headers: { "X-XSRF-TOKEN": csrfToken },
|
||||
retryDelays: [0, 3000, 6000, 12000],
|
||||
retryDelays: [0, 3000, 6000],
|
||||
chunkSize: 20000,
|
||||
metadata: {
|
||||
assignmentId: id,
|
||||
|
|
@ -571,18 +713,19 @@ export default function FormTaskTa() {
|
|||
req.getUnderlyingObject().withCredentials = true;
|
||||
},
|
||||
|
||||
onError(err) {
|
||||
console.error("Upload error:", err);
|
||||
reject(err);
|
||||
onError(error) {
|
||||
reject(error);
|
||||
},
|
||||
|
||||
onSuccess() {
|
||||
console.log("Upload selesai:", file.name);
|
||||
resolve(true);
|
||||
},
|
||||
});
|
||||
|
||||
upload.start();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -718,6 +861,7 @@ export default function FormTaskTa() {
|
|||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
{!isMabesApprover && (
|
||||
<div className="mt-5 space-y-2">
|
||||
<Label>
|
||||
{t("areas-expertise", { defaultValue: "Areas Expertise" })}
|
||||
|
|
@ -735,6 +879,8 @@ export default function FormTaskTa() {
|
|||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!isMabesApprover && (
|
||||
<div className="mt-5 space-y-2">
|
||||
<Label>
|
||||
{t("choose-expert", { defaultValue: "Choose Expert" })}
|
||||
|
|
@ -762,8 +908,12 @@ export default function FormTaskTa() {
|
|||
className="mr-3"
|
||||
/>
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="font-bold">{expert.fullname}</div>
|
||||
<div className="italic">({expert.username})</div>
|
||||
<div className="font-bold">
|
||||
{expert.fullname}
|
||||
</div>
|
||||
<div className="italic">
|
||||
({expert.username})
|
||||
</div>
|
||||
</div>
|
||||
</Label>
|
||||
</div>
|
||||
|
|
@ -813,6 +963,7 @@ export default function FormTaskTa() {
|
|||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-5 space-y-2">
|
||||
<Label>{t("description", { defaultValue: "Description" })}</Label>
|
||||
<Controller
|
||||
|
|
@ -946,7 +1097,9 @@ export default function FormTaskTa() {
|
|||
<Input
|
||||
type="url"
|
||||
className="border rounded p-2 w-full"
|
||||
placeholder={`Masukkan link berita ${index + 1}`}
|
||||
placeholder={`Masukkan link berita ${
|
||||
index + 1
|
||||
} | Contoh: https://www.detik.com`}
|
||||
value={link}
|
||||
onChange={(e) =>
|
||||
handleLinkChange(index, e.target.value)
|
||||
|
|
|
|||
|
|
@ -168,6 +168,13 @@ export function getMenuList(pathname: string, t: any): Group[] {
|
|||
icon: "heroicons:shopping-cart",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
href: "/contributor/task-ta",
|
||||
label: "penugasan TA",
|
||||
active: pathname.includes("/contributor/task-ta"),
|
||||
icon: "heroicons:shopping-cart",
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue