926 lines
29 KiB
TypeScript
926 lines
29 KiB
TypeScript
"use client";
|
|
import React, { useEffect, useRef, useState } from "react";
|
|
import { useForm, Controller } from "react-hook-form";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Card } from "@/components/ui/card";
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
import * as z from "zod";
|
|
import Swal from "sweetalert2";
|
|
import withReactContent from "sweetalert2-react-content";
|
|
import { useParams, useRouter } from "next/navigation";
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
import { Checkbox } from "@/components/ui/checkbox";
|
|
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
|
import JoditEditor from "jodit-react";
|
|
import {
|
|
createAssignmentResponse,
|
|
createTask,
|
|
deleteAssignmentResponse,
|
|
deleteTask,
|
|
finishTask,
|
|
forwardTask,
|
|
getAcceptance,
|
|
getAssignmentResponseList,
|
|
getTask,
|
|
getUserLevelForAssignments,
|
|
} from "@/service/task";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from "@/components/ui/dialog";
|
|
import { ChevronDown, ChevronUp, DotSquare, TrashIcon } from "lucide-react";
|
|
import dynamic from "next/dynamic";
|
|
import { Link } from "@/components/navigation";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import { close, error, loading } from "@/lib/swal";
|
|
import { getCookiesDecrypt } from "@/lib/utils";
|
|
import { Avatar, AvatarImage } from "@/components/ui/avatar";
|
|
|
|
const taskSchema = z.object({
|
|
// uniqueCode: z.string().min(1, { message: "Judul diperlukan" }),
|
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
|
naration: z.string().min(2, {
|
|
message: "Narasi Penugasan harus lebih dari 2 karakter.",
|
|
}),
|
|
forwardMessage: z.string().min(2, {
|
|
message: "Narasi Penugasan harus lebih dari 2 karakter.",
|
|
}),
|
|
});
|
|
|
|
export type taskDetail = {
|
|
id: number;
|
|
uniqueCode: string;
|
|
title: string;
|
|
fileTypeOutput: string;
|
|
assignedToRole: string;
|
|
assignedToTopLevel: string;
|
|
assignmentType: {
|
|
id: number;
|
|
name: string;
|
|
};
|
|
assignmentMainType: {
|
|
id: number;
|
|
name: string;
|
|
};
|
|
createdBy: {
|
|
id: number;
|
|
fullname: string;
|
|
username: string | null;
|
|
email: string;
|
|
isActive: boolean;
|
|
isDefault: boolean;
|
|
isInternational: boolean;
|
|
userLevel: {
|
|
id: number;
|
|
name: string;
|
|
aliasName: string;
|
|
userGroupId: number;
|
|
};
|
|
};
|
|
taskType: string;
|
|
broadcastType: string;
|
|
narration: string;
|
|
is_active: string;
|
|
isDone: any;
|
|
};
|
|
|
|
interface ListData {
|
|
id: number;
|
|
name: string;
|
|
content: string;
|
|
timestamp: string;
|
|
}
|
|
|
|
const ViewEditor = dynamic(
|
|
() => {
|
|
return import("@/components/editor/view-editor");
|
|
},
|
|
{ ssr: false }
|
|
);
|
|
|
|
const formatDate = (dateString: string): string => {
|
|
const date = new Date(dateString);
|
|
|
|
// Pastikan validitas tanggal
|
|
if (isNaN(date.getTime())) {
|
|
throw new Error("Invalid date format");
|
|
}
|
|
|
|
// Format tanggal
|
|
const day = date.getDate().toString().padStart(2, "0");
|
|
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
const year = date.getFullYear();
|
|
// const hours = date.getHours().toString().padStart(2, "0");
|
|
|
|
// Gabungkan hasil format
|
|
return `${day}-${month}-${year} `;
|
|
};
|
|
|
|
interface AcceptanceData {
|
|
id: number;
|
|
acceptAt: string;
|
|
// Tambahkan properti lain sesuai dengan struktur data Anda
|
|
}
|
|
|
|
interface AcceptanceData {
|
|
id: number;
|
|
userLevelId: number;
|
|
sentAt: string;
|
|
isAccept: boolean;
|
|
isSent: boolean;
|
|
userLevels: {
|
|
id: number;
|
|
name: string;
|
|
aliasName: string;
|
|
};
|
|
}
|
|
|
|
export default function FormTaskForward() {
|
|
const MySwal = withReactContent(Swal);
|
|
const router = useRouter();
|
|
const editor = useRef(null);
|
|
type TaskSchema = z.infer<typeof taskSchema>;
|
|
const { id } = useParams() as { id: string };
|
|
console.log(id);
|
|
|
|
const userLevelNumber = getCookiesDecrypt("ulne");
|
|
const userId = getCookiesDecrypt("uie");
|
|
|
|
// State for various form fields
|
|
const [taskOutput, setTaskOutput] = useState({
|
|
all: false,
|
|
video: false,
|
|
audio: false,
|
|
image: false,
|
|
text: false,
|
|
});
|
|
|
|
// const [assignmentType, setAssignmentType] = useState("mediahub");
|
|
// const [assignmentCategory, setAssignmentCategory] = useState("publication");
|
|
const [mainType, setMainType] = useState<string>("1");
|
|
const [taskType, setTaskType] = useState<string>("atensi-khusus");
|
|
const [broadcastType, setBroadcastType] = useState<string>(""); // untuk Tipe Penugasan
|
|
const [type, setType] = useState<string>("1");
|
|
const [selectedTarget, setSelectedTarget] = useState("all");
|
|
const [detail, setDetail] = useState<taskDetail>();
|
|
const [refresh] = useState(false);
|
|
const [listDest, setListDest] = useState([]); // Data Polda dan Polres
|
|
|
|
const [expandedPolda, setExpandedPolda] = useState([{}]);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [responses, setResponses] = useState<Response[]>([]);
|
|
const [response, setResponse] = useState<string>("");
|
|
const [showInput, setShowInput] = useState<boolean>(false);
|
|
const [listData, setListData] = useState([]);
|
|
const [message, setMessage] = useState<string>("");
|
|
const [sentAcceptance, setSentAcceptance] = useState<AcceptanceData[]>([]);
|
|
const [acceptAcceptance, setAcceptAcceptance] = useState<AcceptanceData[]>(
|
|
[]
|
|
);
|
|
const [modalType, setModalType] = useState<"terkirim" | "diterima" | "">("");
|
|
const [Isloading, setLoading] = useState<boolean>(false);
|
|
const [refreshAcceptance, setRefreshAcceptance] = useState<boolean>(false);
|
|
const [replyingTo, setReplyingTo] = useState<number | null>(null);
|
|
const [forwardMessage, setForwardMessage] = useState();
|
|
const [narration, setNarration] = useState(null);
|
|
const [checkedLevels, setCheckedLevels] = useState(new Set());
|
|
|
|
const [platformTypeVisible, setPlatformTypeVisible] = useState(false);
|
|
const [unitSelection, setUnitSelection] = useState({
|
|
allUnit: false,
|
|
mabes: false,
|
|
polda: false,
|
|
polres: false,
|
|
});
|
|
|
|
const {
|
|
control,
|
|
register,
|
|
handleSubmit,
|
|
formState: { errors },
|
|
} = useForm<TaskSchema>({
|
|
resolver: zodResolver(taskSchema),
|
|
});
|
|
|
|
// const handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
// const selectedValue = Number(event.target.value);
|
|
// setMainType(selectedValue);
|
|
|
|
// setPlatformTypeVisible(selectedValue === 2);
|
|
// };
|
|
|
|
useEffect(() => {
|
|
async function fetchPoldaPolres() {
|
|
setIsLoading(true);
|
|
try {
|
|
const response = await getUserLevelForAssignments();
|
|
setListDest(response?.data?.data.list);
|
|
const initialExpandedState = response?.data?.data.list.reduce(
|
|
(acc: any, polda: any) => {
|
|
acc[polda.id] = false;
|
|
return acc;
|
|
},
|
|
{}
|
|
);
|
|
setExpandedPolda(initialExpandedState);
|
|
console.log("polres", initialExpandedState);
|
|
} catch (error) {
|
|
console.error("Error fetching Polda/Polres data:", error);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
}
|
|
fetchPoldaPolres();
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
async function initState() {
|
|
if (id) {
|
|
const response = await getTask(id);
|
|
const details = response?.data?.data;
|
|
|
|
setDetail(details);
|
|
|
|
if (details?.assignedToLevel) {
|
|
const levels = new Set(
|
|
details.assignedToLevel.split(",").map(Number)
|
|
);
|
|
setCheckedLevels(levels);
|
|
}
|
|
}
|
|
}
|
|
initState();
|
|
}, [id, refresh]);
|
|
|
|
useEffect(() => {
|
|
if (detail?.broadcastType) {
|
|
setBroadcastType(detail.broadcastType); // Mengatur nilai broadcastType dari API
|
|
}
|
|
}, [detail?.broadcastType]);
|
|
|
|
useEffect(() => {
|
|
if (detail?.fileTypeOutput) {
|
|
const outputSet = new Set(detail.fileTypeOutput.split(",").map(Number)); // Membagi string ke dalam array dan mengonversi ke nomor
|
|
setTaskOutput({
|
|
all: outputSet.has(0),
|
|
video: outputSet.has(2),
|
|
audio: outputSet.has(4),
|
|
image: outputSet.has(1),
|
|
text: outputSet.has(3),
|
|
});
|
|
}
|
|
}, [detail?.fileTypeOutput]);
|
|
|
|
useEffect(() => {
|
|
if (detail?.assignedToTopLevel) {
|
|
const outputSet = new Set(
|
|
detail.assignedToTopLevel.split(",").map(Number)
|
|
);
|
|
setUnitSelection({
|
|
allUnit: outputSet.has(0),
|
|
mabes: outputSet.has(1),
|
|
polda: outputSet.has(2),
|
|
polres: outputSet.has(3),
|
|
});
|
|
}
|
|
}, [detail?.fileTypeOutput]);
|
|
|
|
const save = async (data: TaskSchema) => {
|
|
const fileTypeMapping = {
|
|
all: "1",
|
|
video: "2",
|
|
audio: "3",
|
|
image: "4",
|
|
text: "5",
|
|
};
|
|
|
|
const selectedOutputs = Object.keys(taskOutput)
|
|
.filter((key) => taskOutput[key as keyof typeof taskOutput])
|
|
.map((key) => fileTypeMapping[key as keyof typeof fileTypeMapping])
|
|
.join(",");
|
|
|
|
const requestData = {
|
|
...data,
|
|
// assignmentType,
|
|
// assignmentCategory,
|
|
target: selectedTarget,
|
|
unitSelection,
|
|
assignedToRole: "3",
|
|
taskType: taskType,
|
|
broadcastType: broadcastType,
|
|
assignmentMainTypeId: mainType,
|
|
assignmentPurpose: "1",
|
|
assignmentTypeId: type,
|
|
fileTypeOutput: selectedOutputs,
|
|
id: null,
|
|
narration: data.naration,
|
|
platformType: "",
|
|
title: data.title,
|
|
};
|
|
|
|
const response = await createTask(requestData);
|
|
|
|
console.log("Form Data Submitted:", requestData);
|
|
console.log("response", response);
|
|
|
|
MySwal.fire({
|
|
title: "Sukses",
|
|
text: "Data berhasil disimpan.",
|
|
icon: "success",
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "OK",
|
|
}).then(() => {
|
|
router.push("/en/contributor/task");
|
|
});
|
|
};
|
|
|
|
const onSubmit = (data: TaskSchema) => {
|
|
MySwal.fire({
|
|
title: "Simpan Data",
|
|
text: "Apakah Anda yakin ingin menyimpan data ini?",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "Simpan",
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
save(data);
|
|
}
|
|
});
|
|
};
|
|
|
|
const successConfirm = () => {
|
|
MySwal.fire({
|
|
title: "Sukses",
|
|
icon: "success",
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "OK",
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
router.push("/en/contributor/task");
|
|
}
|
|
});
|
|
};
|
|
|
|
const handlePoldaPolresChange = () => {
|
|
return Array.from(checkedLevels).join(",");
|
|
};
|
|
|
|
async function saveForward() {
|
|
console.log("Narasi :", narration);
|
|
loading();
|
|
const data = {
|
|
id,
|
|
forwardMessage,
|
|
assignedToLevel: handlePoldaPolresChange(),
|
|
};
|
|
|
|
const response = await forwardTask(data);
|
|
|
|
if (response?.error) {
|
|
error(response.message);
|
|
return false;
|
|
}
|
|
|
|
successConfirm();
|
|
return false;
|
|
}
|
|
|
|
const handleCheckboxChange = (levelId: any) => {
|
|
setCheckedLevels((prev: any) => {
|
|
const updatedLevels = new Set(prev);
|
|
if (updatedLevels.has(levelId)) {
|
|
updatedLevels.delete(levelId);
|
|
} else {
|
|
updatedLevels.add(levelId);
|
|
}
|
|
return updatedLevels;
|
|
});
|
|
};
|
|
|
|
const toggleExpand = (poldaId: any) => {
|
|
setExpandedPolda((prev: any) => ({
|
|
...prev,
|
|
[poldaId]: !prev[poldaId],
|
|
}));
|
|
};
|
|
|
|
useEffect(() => {
|
|
async function initState() {
|
|
// loading();
|
|
const response = await getAssignmentResponseList(id);
|
|
console.log("data", response?.data?.data);
|
|
console.log("userLvl", userLevelNumber);
|
|
setListData(response?.data?.data);
|
|
close();
|
|
}
|
|
|
|
initState();
|
|
}, []);
|
|
|
|
const handleToggleInput = (): void => {
|
|
setShowInput(!showInput);
|
|
};
|
|
|
|
const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
setMessage(e.target.value);
|
|
};
|
|
|
|
const postData = () => {
|
|
sendSuggestionParent();
|
|
};
|
|
|
|
const sendReplyData = async (parentId: number) => {
|
|
const inputElement = document.querySelector(
|
|
`#input-comment-${parentId}`
|
|
) as HTMLTextAreaElement;
|
|
|
|
if (inputElement?.value?.length > 1) {
|
|
loading();
|
|
const data = {
|
|
assignmentId: id,
|
|
message: inputElement.value,
|
|
parentId,
|
|
};
|
|
|
|
console.log(data);
|
|
const response = await createAssignmentResponse(data);
|
|
console.log(response);
|
|
|
|
const responseGet = await getAssignmentResponseList(id);
|
|
console.log(responseGet?.data?.data);
|
|
setListData(responseGet?.data?.data);
|
|
|
|
inputElement.value = "";
|
|
close();
|
|
setReplyingTo(null);
|
|
}
|
|
};
|
|
|
|
async function sendSuggestionParent() {
|
|
if (message?.length > 1) {
|
|
loading();
|
|
const data = {
|
|
assignmentId: id,
|
|
message,
|
|
parentId: null,
|
|
};
|
|
|
|
const response = await createAssignmentResponse(data);
|
|
|
|
console.log(response);
|
|
setMessage("");
|
|
const responseGet = await getAssignmentResponseList(id);
|
|
console.log(responseGet?.data?.data);
|
|
setListData(responseGet?.data?.data);
|
|
|
|
close();
|
|
}
|
|
}
|
|
|
|
async function deleteDataSuggestion(dataId: any) {
|
|
loading();
|
|
const response = await deleteAssignmentResponse(dataId);
|
|
console.log(response);
|
|
const responseGet = await getAssignmentResponseList(id);
|
|
console.log(responseGet?.data?.data);
|
|
setListData(responseGet?.data?.data);
|
|
close();
|
|
}
|
|
|
|
const deleteData = (dataId: any) => {
|
|
deleteDataSuggestion(dataId);
|
|
console.log(dataId);
|
|
};
|
|
|
|
async function getListAcceptance(): Promise<void> {
|
|
const isAccept = true;
|
|
|
|
try {
|
|
const resSent = await getAcceptance(id, !isAccept);
|
|
setSentAcceptance(resSent?.data?.data);
|
|
|
|
const resAccept = await getAcceptance(id, isAccept);
|
|
|
|
const acceptanceSort = resAccept?.data?.data?.sort(
|
|
(a: AcceptanceData, b: AcceptanceData) =>
|
|
new Date(a.acceptAt).getTime() - new Date(b.acceptAt).getTime()
|
|
);
|
|
|
|
console.log("Data sort:", acceptanceSort);
|
|
setAcceptAcceptance(acceptanceSort);
|
|
} catch (error) {
|
|
console.error("Error fetching acceptance data:", error);
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
async function initState(): Promise<void> {
|
|
await getListAcceptance();
|
|
}
|
|
|
|
initState();
|
|
}, [refreshAcceptance]);
|
|
|
|
const setFinishAcceptance = async (
|
|
id: number,
|
|
isFinish: boolean
|
|
): Promise<void> => {
|
|
if (!isFinish) {
|
|
loading();
|
|
|
|
setRefreshAcceptance((prev) => !prev);
|
|
close();
|
|
}
|
|
};
|
|
|
|
const handleReply = (id: any) => {
|
|
setReplyingTo(id);
|
|
};
|
|
|
|
async function finishAssignment() {
|
|
const response = finishTask(id);
|
|
|
|
// if (response.error) {
|
|
// error(response.message);
|
|
// return false;
|
|
// }
|
|
|
|
successConfirm();
|
|
}
|
|
|
|
async function deleteAssignment() {
|
|
const response = deleteTask(id);
|
|
|
|
// if (response.error) {
|
|
// error(response.message);
|
|
// return false;
|
|
// }
|
|
|
|
successConfirm();
|
|
}
|
|
|
|
async function handleForward() {
|
|
MySwal.fire({
|
|
title: "Forward Penugasan?",
|
|
text: "",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "Ya",
|
|
cancelButtonText: "Tidak",
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
saveForward();
|
|
}
|
|
});
|
|
}
|
|
async function handleDeleteAssignment() {
|
|
MySwal.fire({
|
|
title: "Apakah Anda yakin ingin menghapus data?",
|
|
text: "",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "Hapus",
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
deleteAssignment();
|
|
}
|
|
});
|
|
}
|
|
|
|
async function handleAssignmentDone() {
|
|
MySwal.fire({
|
|
title: "Apakah tugas sudah selesai?",
|
|
text: "",
|
|
icon: "warning",
|
|
showCancelButton: true,
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonColor: "#3085d6",
|
|
confirmButtonText: "Ya",
|
|
cancelButtonText: "Tidak",
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
finishAssignment();
|
|
}
|
|
});
|
|
}
|
|
|
|
return (
|
|
<Card>
|
|
{detail !== undefined ? (
|
|
<div className="px-6 py-6">
|
|
<div className="flex flex-row justify-between">
|
|
<p className="text-lg font-semibold mb-3">Tujuan Forward</p>
|
|
</div>
|
|
|
|
<form onSubmit={handleSubmit(onSubmit)}>
|
|
<div className="gap-5 mb-5">
|
|
<div className="grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto">
|
|
{listDest.map((polda: any) => (
|
|
<div key={polda.id} className="border p-2">
|
|
<Label className="flex items-center">
|
|
<Checkbox
|
|
checked={checkedLevels.has(polda.id)}
|
|
onCheckedChange={() => handleCheckboxChange(polda.id)}
|
|
className="mr-3"
|
|
/>
|
|
{polda.name}
|
|
<button
|
|
onClick={() => toggleExpand(polda.id)}
|
|
className="ml-2 focus:outline-none"
|
|
></button>
|
|
</Label>
|
|
</div>
|
|
))}
|
|
</div>
|
|
<div className="form-group mt-2">
|
|
<Label htmlFor="message">Pesan</Label>
|
|
<Textarea
|
|
id="forwardMessage"
|
|
placeholder="Message"
|
|
{...register("forwardMessage")}
|
|
/>
|
|
</div>
|
|
<Button
|
|
color="primary"
|
|
variant={"default"}
|
|
type="button"
|
|
className="btn btn-primary mr-2 float-right my-3"
|
|
onClick={() => handleForward()}
|
|
>
|
|
Forward Tugas
|
|
</Button>
|
|
<div className="space-y-2 mt-6">
|
|
<Label>Judul</Label>
|
|
<Controller
|
|
control={control}
|
|
name="title"
|
|
render={({ field }) => (
|
|
<Input
|
|
size="md"
|
|
type="text"
|
|
value={detail?.title}
|
|
onChange={field.onChange}
|
|
placeholder="Enter Title"
|
|
/>
|
|
)}
|
|
/>
|
|
{errors.title?.message && (
|
|
<p className="text-red-400 text-sm">{errors.title.message}</p>
|
|
)}
|
|
</div>
|
|
<div className="flex flex-row items-center">
|
|
<div className="mt-6">
|
|
<Label>Tujuan Pemilihan Tugas</Label>
|
|
<Select
|
|
onValueChange={setSelectedTarget}
|
|
value={detail.assignedToRole}
|
|
>
|
|
<SelectTrigger size="md">
|
|
<SelectValue placeholder="Pilih" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="3,4">Semua Pengguna</SelectItem>
|
|
<SelectItem value="4">Kontributor</SelectItem>
|
|
<SelectItem value="3">Approver</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
<div className="flex flex-wrap gap-3 mt-6 pt-5 ml-3">
|
|
{Object.keys(unitSelection).map((key) => (
|
|
<div className="flex items-center gap-2" key={key}>
|
|
<Checkbox
|
|
id={key}
|
|
disabled
|
|
checked={
|
|
unitSelection[key as keyof typeof unitSelection]
|
|
}
|
|
onCheckedChange={(value) =>
|
|
setUnitSelection({ ...unitSelection, [key]: value })
|
|
}
|
|
/>
|
|
<Label htmlFor={key}>
|
|
{key.charAt(0).toUpperCase() + key.slice(1)}
|
|
</Label>
|
|
</div>
|
|
))}
|
|
</div>
|
|
<div className="mt-6 pt-5 pl-3">
|
|
<Dialog>
|
|
<DialogTrigger asChild>
|
|
<Button variant="soft" size="sm" color="primary">
|
|
[Kustom]
|
|
</Button>
|
|
</DialogTrigger>
|
|
<DialogContent className="sm:max-w-[425px] md:max-w-[500px] lg:max-w-[1500px]">
|
|
<DialogHeader>
|
|
<DialogTitle>
|
|
Daftar Wilayah Polda dan Polres
|
|
</DialogTitle>
|
|
</DialogHeader>
|
|
<div className="grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto">
|
|
{listDest.map((polda: any) => (
|
|
<div key={polda.id} className="border p-2">
|
|
<Label className="flex items-center">
|
|
<Checkbox
|
|
disabled
|
|
checked={checkedLevels.has(polda.id)}
|
|
onCheckedChange={() =>
|
|
handleCheckboxChange(polda.id)
|
|
}
|
|
className="mr-3"
|
|
/>
|
|
{polda.name}
|
|
<button
|
|
onClick={() => toggleExpand(polda.id)}
|
|
className="ml-2 focus:outline-none"
|
|
>
|
|
{expandedPolda[polda.id] ? (
|
|
<ChevronUp size={16} />
|
|
) : (
|
|
<ChevronDown size={16} />
|
|
)}
|
|
</button>
|
|
</Label>
|
|
{expandedPolda[polda.id] && (
|
|
<div className="ml-6 mt-2">
|
|
<Label className="block">
|
|
<Checkbox
|
|
disabled
|
|
checked={polda?.subDestination?.every(
|
|
(polres: any) =>
|
|
checkedLevels.has(polres.id)
|
|
)}
|
|
onCheckedChange={(isChecked) => {
|
|
const updatedLevels = new Set(
|
|
checkedLevels
|
|
);
|
|
polda?.subDestination?.forEach(
|
|
(polres: any) => {
|
|
if (isChecked) {
|
|
updatedLevels.add(polres.id);
|
|
} else {
|
|
updatedLevels.delete(polres.id);
|
|
}
|
|
}
|
|
);
|
|
setCheckedLevels(updatedLevels);
|
|
}}
|
|
className="mr-2"
|
|
/>
|
|
Pilih Semua Polres
|
|
</Label>
|
|
{polda?.subDestination?.map((polres: any) => (
|
|
<Label key={polres.id} className="block mt-1">
|
|
<Checkbox
|
|
disabled
|
|
checked={checkedLevels.has(polres.id)}
|
|
onCheckedChange={() =>
|
|
handleCheckboxChange(polres.id)
|
|
}
|
|
className="mr-2"
|
|
/>
|
|
{polres.name}
|
|
</Label>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
))}
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</div>
|
|
</div>
|
|
<div className="mt-6">
|
|
<Label>Tipe Penugasan</Label>
|
|
<RadioGroup
|
|
value={detail.assignmentMainType.id.toString()}
|
|
onValueChange={(value) => setMainType(value)}
|
|
// value={String(mainType)}
|
|
// onValueChange={(value) => setMainType(Number(value))}
|
|
className="flex flex-wrap gap-3"
|
|
>
|
|
<RadioGroupItem value="1" id="mediahub" />
|
|
<Label htmlFor="mediahub">Mediahub</Label>
|
|
<RadioGroupItem value="2" id="medsos-mediahub" />
|
|
<Label htmlFor="medsos-mediahub">Medsos Mediahub</Label>
|
|
</RadioGroup>
|
|
</div>
|
|
<div className="mt-6">
|
|
<Label>Jenis Tugas </Label>
|
|
<RadioGroup
|
|
value={detail.taskType.toString()}
|
|
onValueChange={(value) => setTaskType(String(value))}
|
|
className="flex flex-wrap gap-3"
|
|
>
|
|
<RadioGroupItem value="atensi-khusus" id="khusus" />
|
|
<Label htmlFor="atensi-khusus">Atensi Khusus</Label>
|
|
<RadioGroupItem value="tugas-harian" id="harian" />
|
|
<Label htmlFor="tugas-harian">Tugas Harian</Label>
|
|
</RadioGroup>
|
|
</div>
|
|
{/* RadioGroup Assignment Category */}
|
|
<div className="mt-6">
|
|
<Label>Jenis Penugasan</Label>
|
|
<RadioGroup
|
|
value={detail.assignmentType.id.toString()}
|
|
onValueChange={(value) => setType(value)}
|
|
className="flex flex-wrap gap-3"
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<RadioGroupItem value="1" id="publication" />
|
|
<Label htmlFor="publication">Publikasi</Label>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<RadioGroupItem value="2" id="amplification" />
|
|
<Label htmlFor="amplification">Amplifikasi</Label>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<RadioGroupItem value="3" id="contra" />
|
|
<Label htmlFor="contra">Kontra</Label>
|
|
</div>
|
|
</RadioGroup>
|
|
</div>
|
|
<div className="mt-6">
|
|
<Label>Output Tugas</Label>
|
|
<div className="flex flex-wrap gap-3">
|
|
{Object.keys(taskOutput).map((key) => (
|
|
<div className="flex items-center gap-2" key={key}>
|
|
<Checkbox
|
|
id={key}
|
|
disabled
|
|
checked={taskOutput[key as keyof typeof taskOutput]}
|
|
onCheckedChange={(value) =>
|
|
setTaskOutput({ ...taskOutput, [key]: value })
|
|
}
|
|
/>
|
|
<Label htmlFor={key}>
|
|
{key.charAt(0).toUpperCase() + key.slice(1)}
|
|
</Label>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
{/* <div className="mt-6">
|
|
<Label>Broadcast </Label>
|
|
<RadioGroup
|
|
value={broadcastType}
|
|
onValueChange={(value) => setBroadcastType(value)}
|
|
className="flex flex-wrap gap-3"
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
<RadioGroupItem value="all" id="all" />
|
|
<Label htmlFor="all">Semua</Label>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<RadioGroupItem value="email" id="email" />
|
|
<Label htmlFor="email">Email Blast</Label>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<RadioGroupItem value="whatsapp" id="whatsapp" />
|
|
<Label htmlFor="whatsapp">WhatsApp Blast</Label>
|
|
</div>
|
|
</RadioGroup>
|
|
</div> */}
|
|
<div className="mt-6">
|
|
<Label>Narasi Penugasan</Label>
|
|
<Controller
|
|
control={control}
|
|
name="naration"
|
|
render={({ field: { onChange, value } }) => (
|
|
<ViewEditor initialData={detail?.narration} />
|
|
)}
|
|
/>
|
|
{errors.naration?.message && (
|
|
<p className="text-red-400 text-sm">
|
|
{errors.naration.message}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
) : (
|
|
""
|
|
)}
|
|
</Card>
|
|
);
|
|
}
|