feat: update form content and agenda setting, and task
This commit is contained in:
parent
614b3e36a4
commit
6119ad56be
|
|
@ -1,5 +1,10 @@
|
||||||
// "use client";
|
// "use client";
|
||||||
import React, { useState, useEffect } from "react";
|
import React, {
|
||||||
|
useState,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
Fragment,
|
||||||
|
} from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -32,7 +37,7 @@ import {
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { error, loading } from "@/lib/swal";
|
import { error, loading, success } from "@/lib/swal";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import Swal from "sweetalert2";
|
import Swal from "sweetalert2";
|
||||||
import withReactContent from "sweetalert2-react-content";
|
import withReactContent from "sweetalert2-react-content";
|
||||||
|
|
@ -42,12 +47,18 @@ import { saveAgendaSettings } from "@/service/agenda-setting/agenda-setting";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { getUserLevelForAssignments } from "@/service/task";
|
import { getUserLevelForAssignments } from "@/service/task";
|
||||||
import { AudioRecorder } from "react-audio-voice-recorder";
|
import { AudioRecorder } from "react-audio-voice-recorder";
|
||||||
|
import FileUploaderMultiple from "@/components/form/shared/file-uploaded";
|
||||||
|
import { Upload } from "tus-js-client";
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
title: z.string().min(3, { message: "Required" }),
|
title: z.string().min(3, { message: "Required" }),
|
||||||
description: z.string().min(3, { message: "Required" }),
|
description: z.string().min(3, { message: "Required" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface FileWithPreview extends File {
|
||||||
|
preview: string;
|
||||||
|
}
|
||||||
|
|
||||||
const EventModal = ({
|
const EventModal = ({
|
||||||
open,
|
open,
|
||||||
onClose,
|
onClose,
|
||||||
|
|
@ -64,7 +75,7 @@ const EventModal = ({
|
||||||
const [startDate, setStartDate] = useState<Date>(new Date());
|
const [startDate, setStartDate] = useState<Date>(new Date());
|
||||||
const [endDate, setEndDate] = useState<Date>(new Date());
|
const [endDate, setEndDate] = useState<Date>(new Date());
|
||||||
const [isPending, startTransition] = React.useTransition();
|
const [isPending, startTransition] = React.useTransition();
|
||||||
const [calendarProps, setCalendarProps] = React.useState<any>(
|
const [agendaType, setAgendaType] = React.useState<any>(
|
||||||
categories[0].value
|
categories[0].value
|
||||||
);
|
);
|
||||||
const [listDest, setListDest] = useState([]);
|
const [listDest, setListDest] = useState([]);
|
||||||
|
|
@ -78,6 +89,14 @@ const EventModal = ({
|
||||||
const [audioFile, setAudioFile] = useState<File | null>(null);
|
const [audioFile, setAudioFile] = useState<File | null>(null);
|
||||||
const [isRecording, setIsRecording] = useState(false);
|
const [isRecording, setIsRecording] = useState(false);
|
||||||
const [timer, setTimer] = useState<number>(120);
|
const [timer, setTimer] = useState<number>(120);
|
||||||
|
const [imageFiles, setImageFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [videoFiles, setVideoFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [textFiles, setTextFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [audioFiles, setAudioFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [isImageUploadFinish, setIsImageUploadFinish] = useState(false);
|
||||||
|
const [isVideoUploadFinish, setIsVideoUploadFinish] = useState(false);
|
||||||
|
const [isTextUploadFinish, setIsTextUploadFinish] = useState(false);
|
||||||
|
const [isAudioUploadFinish, setIsAudioUploadFinish] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
|
|
@ -96,8 +115,17 @@ const EventModal = ({
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await getUserLevelForAssignments();
|
const response = await getUserLevelForAssignments();
|
||||||
setListDest(response?.data?.data.list);
|
const levelList = response?.data?.data.list;
|
||||||
const initialExpandedState = response?.data?.data.list.reduce(
|
let listFiltered = [];
|
||||||
|
if (agendaType == "polda") {
|
||||||
|
listFiltered = levelList.filter((level: any) => level.name != 'SATKER POLRI');
|
||||||
|
} else if (agendaType == "polres") {
|
||||||
|
listFiltered = levelList.filter((level: any) => level.name != 'SATKER POLRI');
|
||||||
|
} else if (agendaType == "satker") {
|
||||||
|
listFiltered = levelList.filter((level: any) => level.name == 'SATKER POLRI');
|
||||||
|
}
|
||||||
|
setListDest(listFiltered);
|
||||||
|
const initialExpandedState = listFiltered.reduce(
|
||||||
(acc: any, polda: any) => {
|
(acc: any, polda: any) => {
|
||||||
acc[polda.id] = false;
|
acc[polda.id] = false;
|
||||||
return acc;
|
return acc;
|
||||||
|
|
@ -105,7 +133,6 @@ const EventModal = ({
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
setExpandedPolda(initialExpandedState);
|
setExpandedPolda(initialExpandedState);
|
||||||
console.log("polres", initialExpandedState);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching Polda/Polres data:", error);
|
console.error("Error fetching Polda/Polres data:", error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -113,7 +140,8 @@ const EventModal = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetchPoldaPolres();
|
fetchPoldaPolres();
|
||||||
}, []);
|
console.log("Event", event);
|
||||||
|
}, [agendaType]);
|
||||||
|
|
||||||
const handleCheckboxChange = (levelId: number) => {
|
const handleCheckboxChange = (levelId: number) => {
|
||||||
setCheckedLevels((prev) => {
|
setCheckedLevels((prev) => {
|
||||||
|
|
@ -128,18 +156,15 @@ const EventModal = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const save = async (data: any) => {
|
const save = async (data: any) => {
|
||||||
if (!audioFile) return;
|
// const formData = new FormData();
|
||||||
|
// formData.append("voiceNote", audioFile);
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("voiceNote", audioFile);
|
|
||||||
|
|
||||||
const reqData = {
|
const reqData = {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
agendaType: calendarProps,
|
agendaType: agendaType,
|
||||||
startDate: format(startDate, "yyyy-MM-dd"),
|
startDate: format(startDate, "yyyy-MM-dd"),
|
||||||
endDate: format(endDate, "yyyy-MM-dd"),
|
endDate: format(endDate, "yyyy-MM-dd"),
|
||||||
voiceNote: formData,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("Submitted Data:", reqData);
|
console.log("Submitted Data:", reqData);
|
||||||
|
|
@ -150,20 +175,70 @@ const EventModal = ({
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cookies.set("AgendaSetting", response?.data?.data.id, {
|
const id = response?.data?.data.id;
|
||||||
expires: 1,
|
|
||||||
|
if (imageFiles?.length == 0) {
|
||||||
|
setIsImageUploadFinish(true);
|
||||||
|
}
|
||||||
|
imageFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"1",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (videoFiles?.length == 0) {
|
||||||
|
setIsVideoUploadFinish(true);
|
||||||
|
}
|
||||||
|
videoFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"2",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (textFiles?.length == 0) {
|
||||||
|
setIsTextUploadFinish(true);
|
||||||
|
}
|
||||||
|
textFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"3",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (audioFiles?.length == 0) {
|
||||||
|
setIsAudioUploadFinish(true);
|
||||||
|
}
|
||||||
|
audioFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"4",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Optional: Use Swal for success feedback
|
// Optional: Use Swal for success feedback
|
||||||
MySwal.fire({
|
// MySwal.fire({
|
||||||
title: "Sukses",
|
// title: "Sukses",
|
||||||
text: "Data berhasil disimpan.",
|
// text: "Data berhasil disimpan.",
|
||||||
icon: "success",
|
// icon: "success",
|
||||||
confirmButtonColor: "#3085d6",
|
// confirmButtonColor: "#3085d6",
|
||||||
confirmButtonText: "OK",
|
// confirmButtonText: "OK",
|
||||||
}).then(() => {
|
// }).then(() => {
|
||||||
router.push("en/contributor/agenda-setting");
|
// router.push("en/contributor/agenda-setting");
|
||||||
});
|
// });
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = (data: any) => {
|
const onSubmit = (data: any) => {
|
||||||
|
|
@ -179,7 +254,7 @@ const EventModal = ({
|
||||||
setStartDate(event?.event?.start);
|
setStartDate(event?.event?.start);
|
||||||
setEndDate(event?.event?.end);
|
setEndDate(event?.event?.end);
|
||||||
const eventCalendar = event?.event?.extendedProps?.calendar;
|
const eventCalendar = event?.event?.extendedProps?.calendar;
|
||||||
setCalendarProps(eventCalendar || categories[0].value);
|
setAgendaType(eventCalendar || categories[0].value);
|
||||||
}
|
}
|
||||||
setValue("title", event?.event?.title || "");
|
setValue("title", event?.event?.title || "");
|
||||||
setValue("description", event?.event?.description || "");
|
setValue("description", event?.event?.description || "");
|
||||||
|
|
@ -197,6 +272,7 @@ const EventModal = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleExpand = (poldaId: any) => {
|
const toggleExpand = (poldaId: any) => {
|
||||||
|
console.log("Toogle : ", expandedPolda);
|
||||||
setExpandedPolda((prev: any) => ({
|
setExpandedPolda((prev: any) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[poldaId]: !prev[poldaId],
|
[poldaId]: !prev[poldaId],
|
||||||
|
|
@ -248,6 +324,89 @@ const EventModal = ({
|
||||||
audioElements.forEach((audio) => audio.remove());
|
audioElements.forEach((audio) => audio.remove());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function uploadResumableFile(
|
||||||
|
idx: number,
|
||||||
|
id: string,
|
||||||
|
file: any,
|
||||||
|
fileTypeId: string,
|
||||||
|
duration: string
|
||||||
|
) {
|
||||||
|
console.log(idx, id, file, fileTypeId, duration);
|
||||||
|
|
||||||
|
// const placements = getPlacement(file.placements);
|
||||||
|
// console.log("Placementttt: : ", placements);
|
||||||
|
|
||||||
|
const upload = new Upload(file, {
|
||||||
|
endpoint: `${process.env.NEXT_PUBLIC_API}/agenda-settings/file/upload`,
|
||||||
|
retryDelays: [0, 3000, 6000, 12_000, 24_000],
|
||||||
|
chunkSize: 20_000,
|
||||||
|
metadata: {
|
||||||
|
agendaSettingId: id,
|
||||||
|
filename: file.name,
|
||||||
|
filetype: file.type,
|
||||||
|
fileTypeId: fileTypeId,
|
||||||
|
duration: "",
|
||||||
|
isWatermark: "true", // hardcode
|
||||||
|
},
|
||||||
|
onError: async (e: any) => {
|
||||||
|
console.log("Error upload :", e);
|
||||||
|
error(e);
|
||||||
|
},
|
||||||
|
onChunkComplete: (
|
||||||
|
chunkSize: any,
|
||||||
|
bytesAccepted: any,
|
||||||
|
bytesTotal: any
|
||||||
|
) => {
|
||||||
|
const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100);
|
||||||
|
// progressInfo[idx].percentage = uploadPersen;
|
||||||
|
// counterUpdateProgress++;
|
||||||
|
// console.log(counterUpdateProgress);
|
||||||
|
// setProgressList(progressInfo);
|
||||||
|
// setCounterProgress(counterUpdateProgress);
|
||||||
|
},
|
||||||
|
onSuccess: async () => {
|
||||||
|
// uploadPersen = 100;
|
||||||
|
// progressInfo[idx].percentage = 100;
|
||||||
|
// counterUpdateProgress++;
|
||||||
|
// setCounterProgress(counterUpdateProgress);
|
||||||
|
successTodo();
|
||||||
|
if (fileTypeId == '1'){
|
||||||
|
setIsImageUploadFinish(true);
|
||||||
|
} else if (fileTypeId == '2'){
|
||||||
|
setIsVideoUploadFinish(true);
|
||||||
|
} if (fileTypeId == '3'){
|
||||||
|
setIsTextUploadFinish(true);
|
||||||
|
} if (fileTypeId == '4'){
|
||||||
|
setIsAudioUploadFinish(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
upload.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
successTodo();
|
||||||
|
}, [isImageUploadFinish, isVideoUploadFinish, isAudioUploadFinish, isTextUploadFinish])
|
||||||
|
|
||||||
|
function successTodo() {
|
||||||
|
if (isImageUploadFinish && isVideoUploadFinish && isAudioUploadFinish && isTextUploadFinish) {
|
||||||
|
successSubmit("/in/contributor/agenda-setting");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const successSubmit = (redirect: string) => {
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Sukses",
|
||||||
|
text: "Data berhasil disimpan.",
|
||||||
|
icon: "success",
|
||||||
|
confirmButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "OK",
|
||||||
|
}).then(() => {
|
||||||
|
router.push(redirect);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DeleteConfirmationDialog
|
<DeleteConfirmationDialog
|
||||||
|
|
@ -263,7 +422,7 @@ const EventModal = ({
|
||||||
>
|
>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
{event ? "Edit Agenda Setting" : "Create Agenda Setting"}{" "}
|
{event?.length > 1 ? "Edit Agenda Setting" : "Create Agenda Setting"}{" "}
|
||||||
{event?.title}
|
{event?.title}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
@ -366,14 +525,14 @@ const EventModal = ({
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<Label htmlFor="calendarProps">Jenis Agenda </Label>
|
<Label htmlFor="agendaType">Jenis Agenda </Label>
|
||||||
<Controller
|
<Controller
|
||||||
name="calendarProps"
|
name="agendaType"
|
||||||
control={control}
|
control={control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<Select
|
<Select
|
||||||
value={calendarProps}
|
value={agendaType}
|
||||||
onValueChange={(data) => setCalendarProps(data)}
|
onValueChange={(data) => setAgendaType(data)}
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Label" />
|
<SelectValue placeholder="Label" />
|
||||||
|
|
@ -392,12 +551,12 @@ const EventModal = ({
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{calendarProps === "polda" && (
|
{(agendaType === "polda" || agendaType === "polres" || agendaType === "satker" )&& (
|
||||||
<div>
|
<div>
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button variant="soft" size="sm" color="primary">
|
<Button variant="soft" size="sm" color="primary">
|
||||||
[Kustom]
|
[Pilih {agendaType}]
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent className="sm:max-w-[425px] md:max-w-[500px] lg:max-w-[1500px]">
|
<DialogContent className="sm:max-w-[425px] md:max-w-[500px] lg:max-w-[1500px]">
|
||||||
|
|
@ -429,7 +588,7 @@ const EventModal = ({
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
</Label>
|
</Label>
|
||||||
{expandedPolda[polda.id] && (
|
{(agendaType == "polres" || agendaType == "satker") && expandedPolda[polda.id] && (
|
||||||
<div className="ml-6 mt-2">
|
<div className="ml-6 mt-2">
|
||||||
<Label className="block">
|
<Label className="block">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
|
|
@ -506,29 +665,36 @@ const EventModal = ({
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div>
|
<div>
|
||||||
<Label>Video</Label>
|
<Label>Video</Label>
|
||||||
<Input
|
<FileUploaderMultiple
|
||||||
type="file"
|
accept={{
|
||||||
accept="video/*"
|
"mp4/*": [],
|
||||||
multiple
|
"mov/*": [],
|
||||||
{...register("attachments.video")}
|
}}
|
||||||
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .mp4 atau .mov."
|
||||||
|
onDrop={(files) => setImageFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>Foto</Label>
|
<Label>Foto</Label>
|
||||||
<Input
|
<FileUploaderMultiple
|
||||||
type="file"
|
accept={{
|
||||||
accept="image/*"
|
"image/*": [],
|
||||||
multiple
|
}}
|
||||||
{...register("attachments.photo")}
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .png, .jpg, atau .jpeg."
|
||||||
|
onDrop={(files) => setImageFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>Teks</Label>
|
<Label>Teks</Label>
|
||||||
<Input
|
<FileUploaderMultiple
|
||||||
type="file"
|
accept={{
|
||||||
accept="text/plain"
|
"pdf/*": [],
|
||||||
multiple
|
}}
|
||||||
{...register("attachments.text")}
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .pdf."
|
||||||
|
onDrop={(files) => setTextFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -542,6 +708,16 @@ const EventModal = ({
|
||||||
downloadOnSavePress={true}
|
downloadOnSavePress={true}
|
||||||
downloadFileExtension="webm"
|
downloadFileExtension="webm"
|
||||||
/>
|
/>
|
||||||
|
<FileUploaderMultiple
|
||||||
|
accept={{
|
||||||
|
"mp3/*": [],
|
||||||
|
"wav/*": [],
|
||||||
|
}}
|
||||||
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .mp3 atau .wav."
|
||||||
|
onDrop={(files) => setAudioFiles(files)}
|
||||||
|
className="mt-2"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{audioFile && (
|
{audioFile && (
|
||||||
<div className="flex flex-row justify-between items-center">
|
<div className="flex flex-row justify-between items-center">
|
||||||
|
|
@ -568,15 +744,15 @@ const EventModal = ({
|
||||||
{isPending ? (
|
{isPending ? (
|
||||||
<>
|
<>
|
||||||
<Loader2 className="me-2 h-4 w-4 animate-spin" />
|
<Loader2 className="me-2 h-4 w-4 animate-spin" />
|
||||||
{event ? "Updating..." : "Adding..."}
|
{event?.length > 1 ? "Updating..." : "Adding..."}
|
||||||
</>
|
</>
|
||||||
) : event ? (
|
) : event?.length > 1 ? (
|
||||||
"Update Agenda Setting"
|
"Update Agenda Setting"
|
||||||
) : (
|
) : (
|
||||||
"Simpan Agenda Setting"
|
"Simpan Agenda Setting"
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
{event && (
|
{event?.length > 1 && (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
color="destructive"
|
color="destructive"
|
||||||
|
|
|
||||||
|
|
@ -922,7 +922,7 @@ export default function FormImage() {
|
||||||
// onChange={onChange}
|
// onChange={onChange}
|
||||||
// className="dark:text-black"
|
// className="dark:text-black"
|
||||||
// />
|
// />
|
||||||
<CustomEditor onChange={onChange} />
|
<CustomEditor onChange={onChange} initialData={articleBody || value} />
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
{errors.description?.message && (
|
{errors.description?.message && (
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,127 @@
|
||||||
|
"use client";
|
||||||
|
import { Fragment, useState } from "react";
|
||||||
|
import { Icon } from "@iconify/react";
|
||||||
|
import { Accept, useDropzone } from "react-dropzone";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { CloudUpload } from "lucide-react";
|
||||||
|
|
||||||
|
interface FileWithPreview extends File {
|
||||||
|
preview: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FileUploaderMultipleProps {
|
||||||
|
onDrop: (files: FileWithPreview[]) => void;
|
||||||
|
accept: Accept;
|
||||||
|
maxSize: number;
|
||||||
|
label: string;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const FileUploaderMultiple = ({ onDrop, accept, maxSize, label, className = "", }: FileUploaderMultipleProps) => {
|
||||||
|
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
|
||||||
|
const { getRootProps, getInputProps } = useDropzone({
|
||||||
|
accept,
|
||||||
|
maxSize: maxSize * 1024 * 1024,
|
||||||
|
onDrop: (acceptedFiles) => {
|
||||||
|
const mappedFiles = acceptedFiles.map((file) => Object.assign(file));
|
||||||
|
setFiles((prevFiles) => [...prevFiles, ...mappedFiles]);
|
||||||
|
onDrop(mappedFiles);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const renderFilePreview = (file: FileWithPreview) => {
|
||||||
|
if (file.type.startsWith("image")) {
|
||||||
|
return (
|
||||||
|
<Image
|
||||||
|
width={48}
|
||||||
|
height={48}
|
||||||
|
alt={file.name}
|
||||||
|
src={URL.createObjectURL(file)}
|
||||||
|
className=" rounded border p-0.5"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return <Icon icon="tabler:file-description" />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveFile = (file: FileWithPreview) => {
|
||||||
|
const uploadedFiles = files;
|
||||||
|
const filtered = uploadedFiles.filter((i) => i.name !== file.name);
|
||||||
|
setFiles([...filtered]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveAllFiles = () => {
|
||||||
|
setFiles([]);
|
||||||
|
onDrop([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fileList = files.map((file) => (
|
||||||
|
<div
|
||||||
|
key={file.name}
|
||||||
|
className=" flex justify-between border px-3.5 py-3 my-6 rounded-md"
|
||||||
|
>
|
||||||
|
<div className="flex gap-3 items-center">
|
||||||
|
<div className="file-preview">{renderFilePreview(file)}</div>
|
||||||
|
<div>
|
||||||
|
<div className=" text-sm text-card-foreground">{file.name}</div>
|
||||||
|
<div className=" text-xs font-light text-muted-foreground">
|
||||||
|
{Math.round(file.size / 100) / 10 > 1000 ? (
|
||||||
|
<>{(Math.round(file.size / 100) / 10000).toFixed(1)}</>
|
||||||
|
) : (
|
||||||
|
<>{(Math.round(file.size / 100) / 10).toFixed(1)}</>
|
||||||
|
)}
|
||||||
|
{" kb"}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
color="destructive"
|
||||||
|
variant="outline"
|
||||||
|
className=" border-none rounded-full"
|
||||||
|
onClick={() => handleRemoveFile(file)}
|
||||||
|
>
|
||||||
|
<Icon icon="tabler:x" className=" h-5 w-5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<div {...getRootProps({ className: "dropzone" })} className={className}>
|
||||||
|
<input {...getInputProps()} />
|
||||||
|
<div className=" w-full text-center border-dashed border border-default-200 dark:border-default-300 rounded-md py-[52px] flex items-center flex-col">
|
||||||
|
<CloudUpload className="text-default-300 w-10 h-10" />
|
||||||
|
<h4 className=" text-2xl font-medium mb-1 mt-3 text-card-foreground/80">
|
||||||
|
{/* Drop files here or click to upload. */}
|
||||||
|
Tarik file disini atau klik untuk upload.
|
||||||
|
</h4>
|
||||||
|
<div className=" text-xs text-muted-foreground">
|
||||||
|
( {label}
|
||||||
|
Ukuran maksimal {maxSize} MB.)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{files.length ? (
|
||||||
|
<Fragment>
|
||||||
|
<div>{fileList}</div>
|
||||||
|
<div className=" flex justify-between gap-2">
|
||||||
|
<Button
|
||||||
|
color="destructive"
|
||||||
|
onClick={handleRemoveAllFiles}
|
||||||
|
>
|
||||||
|
Remove All
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Fragment>
|
||||||
|
) : null}
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default FileUploaderMultiple;
|
||||||
|
|
@ -34,6 +34,9 @@ import {
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { ChevronDown, ChevronUp } from "lucide-react";
|
import { ChevronDown, ChevronUp } from "lucide-react";
|
||||||
import { AudioRecorder } from "react-audio-voice-recorder";
|
import { AudioRecorder } from "react-audio-voice-recorder";
|
||||||
|
import FileUploaderMultiple from "@/components/form/shared/file-uploaded";
|
||||||
|
import { Upload } from "tus-js-client";
|
||||||
|
import { error } from "@/config/swal";
|
||||||
|
|
||||||
const taskSchema = z.object({
|
const taskSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -42,6 +45,10 @@ const taskSchema = z.object({
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface FileWithPreview extends File {
|
||||||
|
preview: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type taskDetail = {
|
export type taskDetail = {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -96,6 +103,15 @@ export default function FormTask() {
|
||||||
const [isRecording, setIsRecording] = useState(false);
|
const [isRecording, setIsRecording] = useState(false);
|
||||||
const [timer, setTimer] = useState<number>(120);
|
const [timer, setTimer] = useState<number>(120);
|
||||||
|
|
||||||
|
const [imageFiles, setImageFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [videoFiles, setVideoFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [textFiles, setTextFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [audioFiles, setAudioFiles] = useState<FileWithPreview[]>([]);
|
||||||
|
const [isImageUploadFinish, setIsImageUploadFinish] = useState(false);
|
||||||
|
const [isVideoUploadFinish, setIsVideoUploadFinish] = useState(false);
|
||||||
|
const [isTextUploadFinish, setIsTextUploadFinish] = useState(false);
|
||||||
|
const [isAudioUploadFinish, setIsAudioUploadFinish] = useState(false);
|
||||||
|
|
||||||
const [platformTypeVisible, setPlatformTypeVisible] = useState(false);
|
const [platformTypeVisible, setPlatformTypeVisible] = useState(false);
|
||||||
const [unitSelection, setUnitSelection] = useState({
|
const [unitSelection, setUnitSelection] = useState({
|
||||||
allUnit: false,
|
allUnit: false,
|
||||||
|
|
@ -222,15 +238,69 @@ export default function FormTask() {
|
||||||
console.log("Form Data Submitted:", requestData);
|
console.log("Form Data Submitted:", requestData);
|
||||||
console.log("response", response);
|
console.log("response", response);
|
||||||
|
|
||||||
MySwal.fire({
|
const id = response?.data?.data.id;
|
||||||
title: "Sukses",
|
|
||||||
text: "Data berhasil disimpan.",
|
if (imageFiles?.length == 0) {
|
||||||
icon: "success",
|
setIsImageUploadFinish(true);
|
||||||
confirmButtonColor: "#3085d6",
|
}
|
||||||
confirmButtonText: "OK",
|
imageFiles?.map(async (item: any, index: number) => {
|
||||||
}).then(() => {
|
await uploadResumableFile(
|
||||||
router.push("/en/contributor/task");
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"1",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (videoFiles?.length == 0) {
|
||||||
|
setIsVideoUploadFinish(true);
|
||||||
|
}
|
||||||
|
videoFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"2",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (textFiles?.length == 0) {
|
||||||
|
setIsTextUploadFinish(true);
|
||||||
|
}
|
||||||
|
textFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"3",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (audioFiles?.length == 0) {
|
||||||
|
setIsAudioUploadFinish(true);
|
||||||
|
}
|
||||||
|
audioFiles?.map(async (item: any, index: number) => {
|
||||||
|
await uploadResumableFile(
|
||||||
|
index,
|
||||||
|
String(id),
|
||||||
|
item,
|
||||||
|
"4",
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// MySwal.fire({
|
||||||
|
// title: "Sukses",
|
||||||
|
// text: "Data berhasil disimpan.",
|
||||||
|
// icon: "success",
|
||||||
|
// confirmButtonColor: "#3085d6",
|
||||||
|
// confirmButtonText: "OK",
|
||||||
|
// }).then(() => {
|
||||||
|
// router.push("/en/contributor/task");
|
||||||
|
// });
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = (data: TaskSchema) => {
|
const onSubmit = (data: TaskSchema) => {
|
||||||
|
|
@ -301,6 +371,90 @@ export default function FormTask() {
|
||||||
audioElements.forEach((audio) => audio.remove());
|
audioElements.forEach((audio) => audio.remove());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function uploadResumableFile(
|
||||||
|
idx: number,
|
||||||
|
id: string,
|
||||||
|
file: any,
|
||||||
|
fileTypeId: string,
|
||||||
|
duration: string
|
||||||
|
) {
|
||||||
|
console.log(idx, id, file, fileTypeId, duration);
|
||||||
|
|
||||||
|
// const placements = getPlacement(file.placements);
|
||||||
|
// console.log("Placementttt: : ", placements);
|
||||||
|
|
||||||
|
const upload = new Upload(file, {
|
||||||
|
endpoint: `${process.env.NEXT_PUBLIC_API}/assignment/file/upload`,
|
||||||
|
retryDelays: [0, 3000, 6000, 12_000, 24_000],
|
||||||
|
chunkSize: 20_000,
|
||||||
|
metadata: {
|
||||||
|
assignmentid: id,
|
||||||
|
filename: file.name,
|
||||||
|
filetype: file.type,
|
||||||
|
fileTypeId: fileTypeId,
|
||||||
|
duration: "",
|
||||||
|
isWatermark: "true", // hardcode
|
||||||
|
},
|
||||||
|
onError: async (e: any) => {
|
||||||
|
console.log("Error upload :", e);
|
||||||
|
error(e);
|
||||||
|
},
|
||||||
|
onChunkComplete: (
|
||||||
|
chunkSize: any,
|
||||||
|
bytesAccepted: any,
|
||||||
|
bytesTotal: any
|
||||||
|
) => {
|
||||||
|
const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100);
|
||||||
|
// progressInfo[idx].percentage = uploadPersen;
|
||||||
|
// counterUpdateProgress++;
|
||||||
|
// console.log(counterUpdateProgress);
|
||||||
|
// setProgressList(progressInfo);
|
||||||
|
// setCounterProgress(counterUpdateProgress);
|
||||||
|
},
|
||||||
|
onSuccess: async () => {
|
||||||
|
// uploadPersen = 100;
|
||||||
|
// progressInfo[idx].percentage = 100;
|
||||||
|
// counterUpdateProgress++;
|
||||||
|
// setCounterProgress(counterUpdateProgress);
|
||||||
|
successTodo();
|
||||||
|
if (fileTypeId == '1'){
|
||||||
|
setIsImageUploadFinish(true);
|
||||||
|
} else if (fileTypeId == '2'){
|
||||||
|
setIsVideoUploadFinish(true);
|
||||||
|
} if (fileTypeId == '3'){
|
||||||
|
setIsTextUploadFinish(true);
|
||||||
|
} if (fileTypeId == '4'){
|
||||||
|
setIsAudioUploadFinish(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
upload.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
successTodo();
|
||||||
|
}, [isImageUploadFinish, isVideoUploadFinish, isAudioUploadFinish, isTextUploadFinish])
|
||||||
|
|
||||||
|
function successTodo() {
|
||||||
|
if (isImageUploadFinish && isVideoUploadFinish && isAudioUploadFinish && isTextUploadFinish) {
|
||||||
|
successSubmit("/in/contributor/agenda-setting");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const successSubmit = (redirect: string) => {
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Sukses",
|
||||||
|
text: "Data berhasil disimpan.",
|
||||||
|
icon: "success",
|
||||||
|
confirmButtonColor: "#3085d6",
|
||||||
|
confirmButtonText: "OK",
|
||||||
|
}).then(() => {
|
||||||
|
router.push(redirect);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<div className="px-6 py-6">
|
<div className="px-6 py-6">
|
||||||
|
|
@ -550,34 +704,41 @@ export default function FormTask() {
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5 mt-5">
|
||||||
<Label htmlFor="attachments">Lampiran</Label>
|
<Label htmlFor="attachments">Lampiran</Label>
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div>
|
<div>
|
||||||
<Label>Video</Label>
|
<Label>Video</Label>
|
||||||
<Input
|
<FileUploaderMultiple
|
||||||
type="file"
|
accept={{
|
||||||
accept="video/*"
|
"mp4/*": [],
|
||||||
multiple
|
"mov/*": [],
|
||||||
// {...register("attachments.video")}
|
}}
|
||||||
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .mp4 atau .mov."
|
||||||
|
onDrop={(files) => setImageFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>Foto</Label>
|
<Label>Foto</Label>
|
||||||
<Input
|
<FileUploaderMultiple
|
||||||
type="file"
|
accept={{
|
||||||
accept="image/*"
|
"image/*": [],
|
||||||
multiple
|
}}
|
||||||
// {...register("attachments.photo")}
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .png, .jpg, atau .jpeg."
|
||||||
|
onDrop={(files) => setImageFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Label>Teks</Label>
|
<Label>Teks</Label>
|
||||||
<Input
|
<FileUploaderMultiple
|
||||||
type="file"
|
accept={{
|
||||||
accept="text/plain"
|
"pdf/*": [],
|
||||||
multiple
|
}}
|
||||||
// {...register("attachments.text")}
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .pdf."
|
||||||
|
onDrop={(files) => setTextFiles(files)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -591,6 +752,16 @@ export default function FormTask() {
|
||||||
downloadOnSavePress={true}
|
downloadOnSavePress={true}
|
||||||
downloadFileExtension="webm"
|
downloadFileExtension="webm"
|
||||||
/>
|
/>
|
||||||
|
<FileUploaderMultiple
|
||||||
|
accept={{
|
||||||
|
"mp3/*": [],
|
||||||
|
"wav/*": [],
|
||||||
|
}}
|
||||||
|
maxSize={100}
|
||||||
|
label="Upload file dengan format .mp3 atau .wav."
|
||||||
|
onDrop={(files) => setAudioFiles(files)}
|
||||||
|
className="mt-2"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
{audioFile && (
|
{audioFile && (
|
||||||
<div className="flex flex-row justify-between items-center">
|
<div className="flex flex-row justify-between items-center">
|
||||||
|
|
@ -605,7 +776,9 @@ export default function FormTask() {
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{isRecording && <p>Recording... {timer} seconds remaining</p>}{" "}
|
{isRecording && (
|
||||||
|
<p>Recording... {timer} seconds remaining</p>
|
||||||
|
)}{" "}
|
||||||
{/* Display remaining time */}
|
{/* Display remaining time */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -59,24 +59,7 @@ export async function listDataTeks(limit: any, page: any, isForSelf: any, isAppr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
export async function listDataAudio(
|
|
||||||
limit: any,
|
|
||||||
page: any,
|
|
||||||
isForSelf: any,
|
|
||||||
isApproval: any,
|
|
||||||
categoryFilter: any,
|
|
||||||
statusFilter: any,
|
|
||||||
needApprovalFromLevel: any,
|
|
||||||
creator: any,
|
|
||||||
source: any,
|
|
||||||
startDate: any,
|
|
||||||
endDate: any,
|
|
||||||
title: string = ""
|
|
||||||
) {
|
|
||||||
=======
|
|
||||||
export async function listDataAudio(page: any, limit: any, isForSelf: any, isApproval: any, categoryFilter: any, statusFilter: any, needApprovalFromLevel: any, creator: any, source: any, startDate: any, endDate: any, title: string = "") {
|
export async function listDataAudio(page: any, limit: any, isForSelf: any, isApproval: any, categoryFilter: any, statusFilter: any, needApprovalFromLevel: any, creator: any, source: any, startDate: any, endDate: any, title: string = "") {
|
||||||
>>>>>>> 247f9af4015f7f700a54f09bbe1c1f99b91c71fd
|
|
||||||
return await httpGetInterceptor(
|
return await httpGetInterceptor(
|
||||||
`media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=4&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}`
|
`media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&typeId=4&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}`
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import axiosInterceptorInstance from "./axios-interceptor-instance";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
|
||||||
export async function httpGetInterceptor(pathUrl: any) {
|
export async function httpGetInterceptor(pathUrl: any) {
|
||||||
|
const pathname = window.location.pathname;
|
||||||
const response = await axiosInterceptorInstance
|
const response = await axiosInterceptorInstance
|
||||||
.get(pathUrl)
|
.get(pathUrl)
|
||||||
.catch((error) => error.response);
|
.catch((error) => error.response);
|
||||||
|
|
@ -17,7 +18,9 @@ export async function httpGetInterceptor(pathUrl: any) {
|
||||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
Object.keys(Cookies.get()).forEach((cookieName) => {
|
||||||
Cookies.remove(cookieName);
|
Cookies.remove(cookieName);
|
||||||
});
|
});
|
||||||
// window.location.href = "/";
|
if (pathname?.includes("/contributor/") || pathname?.includes("/admin/") || pathname?.includes("/supervisor/")) {
|
||||||
|
window.location.href = "/";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
error: true,
|
error: true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue