feat:update agenda setting, detail penugasan

This commit is contained in:
Anang Yusman 2025-02-04 15:08:45 +08:00
parent c9592c0d25
commit a331460cef
5 changed files with 91 additions and 15 deletions

View File

@ -10,7 +10,7 @@ import { Label } from "@/components/ui/label";
import ExternalDraggingevent from "./dragging-events";
import { Calendar } from "@/components/ui/calendar";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Book, Plus } from "lucide-react";
import { Book, CheckSquare2, CheckSquare2Icon, Plus } from "lucide-react";
import { Checkbox } from "@/components/ui/checkbox";
import { EventContentArg } from "@fullcalendar/core";
import EventModal from "./event-modal";
@ -334,11 +334,17 @@ const CalendarView = ({ categories }: CalendarViewProps) => {
const renderEventContent = (eventInfo: any) => {
const { title } = eventInfo.event;
const { isPublish } = eventInfo.event.extendedProps;
const { createdByName } = eventInfo.event.extendedProps;
return (
<>
<p className="ml-1">{title}</p>
<div className="flex flex-row">
{" "}
{isPublish && <CheckSquare2 />}
<p className="ml-1">{title}</p>
</div>
<p className="ml-1 text-xs text-start mt-2">
Created By : {createdByName}
</p>
@ -437,7 +443,10 @@ const CalendarView = ({ categories }: CalendarViewProps) => {
className={`w-full p-1 mb-2 rounded-md text-white text-sm ${bgColor}`}
onClick={() => handleClickListItem(item)}
>
<p className="ml-1">{text}</p>
<div className="flex flex-row items-center">
<CheckSquare2Icon />
<p className="ml-1">{text}</p>
</div>
<p className="ml-1 text-xs text-start mt-2">Created By: {createdBy}</p>
</div>
);

View File

@ -46,6 +46,7 @@ import { postSchedule } from "@/service/schedule/schedule";
import {
deleteAgendaSettings,
getAgendaSettingsById,
publishAgendaSettings,
saveAgendaSettings,
} from "@/service/agenda-setting/agenda-setting";
import { Checkbox } from "@/components/ui/checkbox";
@ -153,6 +154,7 @@ const EventModal = ({
const [selectedPolres, setSelectedPolres] = React.useState([]);
const [wavesurfer, setWavesurfer] = useState<WaveSurfer>();
const [isPlaying, setIsPlaying] = useState(false);
const [isPublishing, setIsPublishing] = useState(false);
const {
register,
@ -293,7 +295,7 @@ const EventModal = ({
});
};
const save = async (data: any) => {
const save = async (data: any, publish = false) => {
const publishTo = [];
if (wilayahPublish.semua) publishTo.push("all");
if (wilayahPublish.nasional) publishTo.push("mabes");
@ -356,6 +358,18 @@ const EventModal = ({
"0" // Optional: Replace with actual duration if available
);
});
if (publish) {
setIsPublishing(true);
const publishResponse = await publishAgendaSettings(id);
setIsPublishing(false);
if (publishResponse?.error) {
error(publishResponse?.message);
return false;
}
success("Agenda berhasil dipublikasikan!");
}
};
const onSubmit = (data: any) => {
@ -1120,9 +1134,18 @@ const EventModal = ({
</div>
{detailData && (
<div>
<Button variant={"outline"} color="primary">
Kirim Ke Mabes
</Button>
{roleId == 11 || roleId == 12 ? (
<Button
variant={"outline"}
color="primary"
onClick={() => save(detailData, true)}
disabled={isPublishing}
>
{isPublishing ? "Publishing..." : "Kirim Ke Mabes"}
</Button>
) : (
""
)}
</div>
)}

View File

@ -30,6 +30,7 @@ import {
getAcceptance,
getAcceptanceAssignmentStatus,
getAssignmentResponseList,
getMediaUpload,
getTask,
getUserLevelForAssignments,
} from "@/service/task";
@ -192,6 +193,7 @@ export default function FormTaskDetail() {
const userLevelNumber = getCookiesDecrypt("ulne");
const userId = getCookiesDecrypt("uie");
const userLevelId = getCookiesDecrypt("ulie");
// State for various form fields
const [taskOutput, setTaskOutput] = useState({
@ -227,6 +229,9 @@ export default function FormTaskDetail() {
[]
);
const [totalPage, setTotalPage] = React.useState(1);
const [dataTable, setDataTable] = React.useState<any[]>([]);
const [totalData, setTotalData] = React.useState<number>(1);
const [imageFiles, setImageFiles] = useState<FileWithPreview[]>([]);
const [videoFiles, setVideoFiles] = useState<FileWithPreview[]>([]);
const [textFiles, setTextFiles] = useState<FileWithPreview[]>([]);
@ -322,6 +327,19 @@ export default function FormTaskDetail() {
fetchPoldaPolres();
}, []);
const fetchFilteredData = async (selectedLevels: any[]) => {
try {
const levels =
selectedLevels.length === 0 ? userLevelId : selectedLevels.join(",");
const response = await getMediaUpload(id, levels);
setUploadResults(response?.data?.data || []);
} catch (error) {
console.error("Error fetching filtered data:", error);
}
};
useEffect(() => {
async function initState() {
if (id) {
@ -330,9 +348,9 @@ export default function FormTaskDetail() {
setDetail(details);
if (details) {
setUploadResults(details.uploadResults || []);
}
// if (details) {
// setUploadResults(details.uploadResults || []);
// }
if (details?.urls) {
// Extract attachmentUrl from each object in urls
@ -432,6 +450,25 @@ export default function FormTaskDetail() {
});
};
const handleCheckboxChangeFilter = async (id: number) => {
setCheckedLevels((prev: any) => {
const updatedLevels = new Set(prev);
if (updatedLevels.has(id)) {
updatedLevels.delete(id);
} else {
updatedLevels.add(id);
}
console.log("Checked Levels:", Array.from(updatedLevels));
// Fetch data dengan filter userLevelId
fetchFilteredData(Array.from(updatedLevels));
return updatedLevels;
});
};
const toggleExpand = (poldaId: any) => {
setExpandedPolda((prev: any) => ({
...prev,
@ -1417,10 +1454,9 @@ export default function FormTaskDetail() {
<div key={polda.id} className="border p-2">
<Label className="flex items-center">
<Checkbox
disabled
checked={checkedLevels.has(polda.id)}
onCheckedChange={() =>
handleCheckboxChange(polda.id)
handleCheckboxChangeFilter(polda.id)
}
className="mr-3"
/>
@ -1440,7 +1476,6 @@ export default function FormTaskDetail() {
<div className="ml-6 mt-2">
<Label className="block">
<Checkbox
disabled
checked={polda?.subDestination?.every(
(polres: any) =>
checkedLevels.has(polres.id)
@ -1467,10 +1502,9 @@ export default function FormTaskDetail() {
{polda?.subDestination?.map((polres: any) => (
<Label key={polres.id} className="block mt-1">
<Checkbox
disabled
checked={checkedLevels.has(polres.id)}
onCheckedChange={() =>
handleCheckboxChange(polres.id)
handleCheckboxChangeFilter(polres.id)
}
className="mr-2"
/>

View File

@ -19,6 +19,11 @@ export async function saveAgendaSettings(data: any) {
return httpPostInterceptor(url, data);
}
export async function publishAgendaSettings(id: any) {
const url = `agenda-settings/publish?id=${id}`;
return httpPostInterceptor(url);
}
export async function getPlanningDailyByTypeId(
page: number,
size = 10,

View File

@ -36,6 +36,11 @@ export async function getTask(id: any) {
return httpGetInterceptor(url);
}
export async function getMediaUpload(id: any, userLevelId: any) {
const url = `/assignment/media-uploads?id=${id}&userLevelId=${userLevelId}`;
return httpGetInterceptor(url);
}
export async function forwardTask(data: any) {
const url = "assignment/forward";
return httpPostInterceptor(url, data);