diff --git a/app/[locale]/(protected)/contributor/agenda-setting/calender-view.tsx b/app/[locale]/(protected)/contributor/agenda-setting/calender-view.tsx index 00ba5260..e3312a26 100644 --- a/app/[locale]/(protected)/contributor/agenda-setting/calender-view.tsx +++ b/app/[locale]/(protected)/contributor/agenda-setting/calender-view.tsx @@ -9,7 +9,7 @@ import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import ExternalDraggingevent from "./dragging-events"; import { Calendar } from "@/components/ui/calendar"; -import { Card, CardContent, CardHeader } from "@/components/ui/card"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Plus } from "lucide-react"; import { Checkbox } from "@/components/ui/checkbox"; import { EventContentArg } from "@fullcalendar/core"; @@ -19,6 +19,12 @@ import { getAgendaSettingsList } from "@/service/agenda-setting/agenda-setting"; import dayjs from "dayjs"; import { getCookiesDecrypt } from "@/lib/utils"; import { CalendarCategory } from "./data"; +import { error } from "@/config/swal"; +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover"; const wait = () => new Promise((resolve) => setTimeout(resolve, 1000)); interface CalendarViewProps { @@ -26,6 +32,21 @@ interface CalendarViewProps { categories: CalendarCategory[]; } +export type CalendarEvent = { + id: string; + title: string; + start: Date; + end: Date; + createBy: string; + createdByName: string; + allDay: boolean; + extendedProps: { + calendar: string; + description: string; + }; +}; + + const INITIAL_YEAR = dayjs().format("YYYY"); const INITIAL_MONTH = dayjs().format("M"); @@ -42,6 +63,33 @@ export interface AgendaSettingsAPIResponse { updatedAt: string; createdById: number | null; } + +interface YearlyData { + january?: Event[]; + february?: Event[]; + march?: Event[]; + april?: Event[]; + may?: Event[]; + june?: Event[]; + july?: Event[]; + august?: Event[]; + september?: Event[]; + october?: Event[]; + november?: Event[]; + december?: Event[]; +} + +interface MonthCardProps { + monthId: keyof YearlyData; + label: string; +} + +interface ListItemProps { + item: any; + text: string + createdBy: string; + bgColor: string; +} interface APIResponse { error: boolean; @@ -63,6 +111,8 @@ const CalendarView = ({ categories }: CalendarViewProps) => { // event canvas state const [sheetOpen, setSheetOpen] = useState(false); const [date, setDate] = React.useState(new Date()); + const [activeView, setActiveView] = useState("dayGridMonth"); + const [yearlyData, setYearlyData] = useState(); const [dragEvents] = useState([ { title: "New Event Planning", id: "101", tag: "business" }, @@ -75,6 +125,7 @@ const CalendarView = ({ categories }: CalendarViewProps) => { useEffect(() => { getCalendarEvents(); + getYearlyEvents(); }, []); const getCalendarEvents = async () => { @@ -82,6 +133,7 @@ const CalendarView = ({ categories }: CalendarViewProps) => { console.log("API Response:", res); if (res?.error) { + error(res?.message); return; } @@ -105,6 +157,15 @@ const CalendarView = ({ categories }: CalendarViewProps) => { console.log("event", events); }; + const getYearlyEvents = async () => { + const res = await getAgendaSettingsList(INITIAL_YEAR, '', ''); + if (res?.error) { + error(res.message); + return false; + } + setYearlyData(res?.data?.data); + } + useEffect(() => { setSelectedCategory(categories?.map((c) => c.value)); }, [categories]); @@ -212,11 +273,13 @@ const CalendarView = ({ categories }: CalendarViewProps) => { // event click const handleEventClick = (arg: any) => { + console.log("Event Click ", arg); setSelectedEventDate(null); setSheetOpen(true); setApiEvents(arg); wait().then(() => (document.body.style.pointerEvents = "auto")); }; + // handle close modal const handleCloseModal = () => { setSheetOpen(false); @@ -225,6 +288,7 @@ const CalendarView = ({ categories }: CalendarViewProps) => { }; const handleDateClick = (arg: any) => { setSheetOpen(true); + console.log("Date :", arg); setSelectedEventDate(arg); setApiEvents([]); wait().then(() => (document.body.style.pointerEvents = "auto")); @@ -266,6 +330,142 @@ const CalendarView = ({ categories }: CalendarViewProps) => { } }; + const handleDateChange = (startDate: string, endDate: string) => { + console.log(startDate + " - " + endDate); + }; + + const handleViewChange = (viewType: string) => { + console.log(viewType); + setActiveView(viewType); + }; + + const months: Array<{ id: keyof YearlyData; label: string }> = [ + { id: 'january', label: 'Januari' }, + { id: 'february', label: 'Februari' }, + { id: 'march', label: 'Maret' }, + { id: 'april', label: 'April' }, + { id: 'may', label: 'Mei' }, + { id: 'june', label: 'Juni' }, + { id: 'july', label: 'Juli' }, + { id: 'august', label: 'Agustus' }, + { id: 'september', label: 'September' }, + { id: 'october', label: 'Oktober' }, + { id: 'november', label: 'November' }, + { id: 'december', label: 'Desember' } + ]; + + const getEventColor = (type: Event['type']): string => { + const colors: Record = { + mabes: 'bg-yellow-500', + polda: 'bg-blue-400', + polres: 'bg-slate-400', + international: 'bg-green-400' + }; + return colors[type]; + }; + + const handleClickListItem = (item: any) => { + const formattedEvent: CalendarEvent = { + id: item.id.toString(), + title: item.title, + start: new Date(item.startDate), + end: new Date(item.endDate), + createBy: "Mabes Polri - Approver", // Sesuaikan dengan data yang sebenarnya jika ada + createdByName: item.createdByName, + allDay: true, + extendedProps: { + calendar: item.agendaType, + description: item.description + } + }; + const finalEvent: any = { + event: formattedEvent + } + + console.log("Event click custom : ", finalEvent); + + setSelectedEventDate(null); + setSheetOpen(true); + setApiEvents(finalEvent); + wait().then(() => (document.body.style.pointerEvents = "auto")); + } + + const ListItem: React.FC = ({ item, text, createdBy, bgColor }) => ( +
handleClickListItem(item)}> +

{text}

+

+ Create By: {createdBy} +

+
+ ); + + const MonthCard: React.FC = (props: any) => { + const { monthId, label } = props; + const events: any = yearlyData?.[monthId]; + const displayedEvents = events?.slice(0, 3); + const hasMoreEvents = events?.length > 3; + return ( +
+
+

{label}

+
+ +
+ {events?.length === 0 ? ( +
+

Belum ada data

+
+ ) : ( + <> + {displayedEvents?.map((event: any, index: number) => ( + + ))} + + {hasMoreEvents && ( + + + + + + + + {label} + + +
+ {events.map((event: any, index: number) => ( + + ))} +
+
+
+
+
+ )} + + )} +
+
+ ); + }; + return ( <>
@@ -344,7 +544,13 @@ const CalendarView = ({ categories }: CalendarViewProps) => { headerToolbar={{ left: "prev,next today", center: "title", - right: "dayGridMonth,listWeek,", + right: "listYear,dayGridMonth,listMonth", + }} + views={{ + listYear: { + type: "dayGridMonth", + buttonText: "Year", + }, }} events={displayedEvents} editable={true} @@ -358,9 +564,47 @@ const CalendarView = ({ categories }: CalendarViewProps) => { eventClassNames={handleClassName} dateClick={handleDateClick} eventClick={handleEventClick} - initialView="dayGridMonth" + initialView="listYear" eventContent={renderEventContent} + viewDidMount={(info) => handleViewChange(info.view.type)} + datesSet={(info: any) => { + console.log(info); + handleDateChange(info.view.currentStart, info.view.currentEnd); + handleViewChange(info.view.type); + }} + viewClassNames={activeView === "listYear" ? "hide-calendar-grid" : ""} /> + + {activeView === "listYear" && ( +
+
+ {months.slice(0, 3).map(month => ( + + ))} +
+ + {/* Second Row */} +
+ {months.slice(3, 6).map(month => ( + + ))} +
+ + {/* Third Row */} +
+ {months.slice(6, 9).map(month => ( + + ))} +
+ + {/* Fourth Row */} +
+ {months.slice(9, 12).map(month => ( + + ))} +
+
+ )}
@@ -376,17 +620,3 @@ const CalendarView = ({ categories }: CalendarViewProps) => { }; export default CalendarView; - -export type CalendarEvent = { - id: string; - title: string; - start: Date; - end: Date; - createBy: string; - createdByName: string; - allDay: boolean; - extendedProps: { - calendar: string; - description: string; - }; -}; diff --git a/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx b/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx index 00e002c8..3b7a5036 100644 --- a/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx +++ b/app/[locale]/(protected)/contributor/agenda-setting/event-modal.tsx @@ -147,6 +147,8 @@ const EventModal = ({ } fetchPoldaPolres(); console.log("Event", event); + + console.log("Event click modal : ", event); }, [agendaType]); const handleCheckboxChange = (levelId: number) => { @@ -299,6 +301,7 @@ const EventModal = ({ const file = new File([blob], "voiceNote.webm", { type: "audio/webm" }); setAudioFile(file); }; + const handleDeleteAudio = () => { // Remove the audio file by setting state to null setAudioFile(null); diff --git a/app/[locale]/(protected)/curator/feedback/page.tsx b/app/[locale]/(protected)/curator/feedback/page.tsx new file mode 100644 index 00000000..5986ffc6 --- /dev/null +++ b/app/[locale]/(protected)/curator/feedback/page.tsx @@ -0,0 +1,95 @@ +"use client"; +import SiteBreadcrumb from "@/components/site-breadcrumb"; +import { Progress } from "@/components/ui/progress"; +import { getUserFeedbacks } from "@/service/master/faq"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { stringify } from "querystring"; +import { useEffect, useState } from "react"; + +export default function UserFeedback() { + const [listData, setListData] = useState([]); + + useEffect(() => { + initState(); + }, []); + async function initState() { + const response = await getUserFeedbacks(); + console.log("ssss", response?.data?.data); + setListData(response?.data?.data); + } + + const renderStar = (count: number) => { + const mapped = [1, 2, 3, 4, 5]; + return ( +
+ {mapped?.map((row) => + row < count + 1 ? ( + + ) : ( + + ) + )} +
+ ); + }; + return ( +
+ +
+

Hasil Feedback

+
+ {listData?.map( + (list: any) => + list?.avgScore !== "NaN" && ( +
+
+

{parseInt(list?.avgScore)}

+ {renderStar(parseInt(list?.avgScore))} +
+

{list?.question}

+
+

Penilaian 5

+ +
+
+

Penilaian 4

+ +
+
+

Penilaian 3

+ +
+
+

Penilaian 2

+ +
+
+

Penilaian 1

+ +
+
+ ) + )} +
+
+
+ ); +} diff --git a/app/[locale]/(protected)/shared/communication/collaboration/components/collabroation-table.tsx b/app/[locale]/(protected)/shared/communication/collaboration/components/collabroation-table.tsx index d778a510..719a3ca8 100644 --- a/app/[locale]/(protected)/shared/communication/collaboration/components/collabroation-table.tsx +++ b/app/[locale]/(protected)/shared/communication/collaboration/components/collabroation-table.tsx @@ -64,7 +64,7 @@ import { listTicketingInternal, } from "@/service/communication/communication"; -const EscalationTable = () => { +const CollaborationTable = () => { const router = useRouter(); const searchParams = useSearchParams(); @@ -254,4 +254,4 @@ const EscalationTable = () => { ); }; -export default EscalationTable; +export default CollaborationTable; diff --git a/app/[locale]/(protected)/shared/communication/collaboration/detail/[id]/page.tsx b/app/[locale]/(protected)/shared/communication/collaboration/detail/[id]/page.tsx index 73d182c9..9d755830 100644 --- a/app/[locale]/(protected)/shared/communication/collaboration/detail/[id]/page.tsx +++ b/app/[locale]/(protected)/shared/communication/collaboration/detail/[id]/page.tsx @@ -69,7 +69,10 @@ export default function CollaborationPage() { loading(); const response = await deleteCollabDiscussion(dataId); console.log(response); - + toast({ + title: "Sukses hapus", + }); + setReplyValue(""); close(); initState(); } @@ -79,7 +82,7 @@ export default function CollaborationPage() { loading(); const data = { ticketId: id, - replyValue, + message: replyValue, parentId: null, }; diff --git a/app/[locale]/(protected)/shared/communication/escalation/components/columns.tsx b/app/[locale]/(protected)/shared/communication/escalation/components/columns.tsx index a8af3677..753f3e80 100644 --- a/app/[locale]/(protected)/shared/communication/escalation/components/columns.tsx +++ b/app/[locale]/(protected)/shared/communication/escalation/components/columns.tsx @@ -100,14 +100,6 @@ const columns: ColumnDef[] = [ View - - - Edit - - - - Delete - ); diff --git a/app/[locale]/(protected)/shared/communication/internal/components/internal-table.tsx b/app/[locale]/(protected)/shared/communication/internal/components/internal-table.tsx index 859559c4..86480b65 100644 --- a/app/[locale]/(protected)/shared/communication/internal/components/internal-table.tsx +++ b/app/[locale]/(protected)/shared/communication/internal/components/internal-table.tsx @@ -62,7 +62,7 @@ import { import { listTicketingInternal } from "@/service/communication/communication"; import { Link } from "@/components/navigation"; -const TableAudio = () => { +const InternalTable = () => { const router = useRouter(); const searchParams = useSearchParams(); @@ -260,4 +260,4 @@ const TableAudio = () => { ); }; -export default TableAudio; +export default InternalTable; diff --git a/app/[locale]/(protected)/shared/communication/page.tsx b/app/[locale]/(protected)/shared/communication/page.tsx index c45afc38..393e33e4 100644 --- a/app/[locale]/(protected)/shared/communication/page.tsx +++ b/app/[locale]/(protected)/shared/communication/page.tsx @@ -1,7 +1,6 @@ "use client"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; -import InternalTable from "./internal/components/internal-table"; import SiteBreadcrumb from "@/components/site-breadcrumb"; import CollaborationTable from "./collaboration/components/collabroation-table"; @@ -10,6 +9,7 @@ import { useState } from "react"; import { Link, useRouter } from "@/i18n/routing"; import { PlusIcon } from "lucide-react"; import { Button } from "@/components/ui/button"; +import InternalTable from "./internal/components/internal-table"; const CommunicationPage = () => { const [tab, setTab] = useState("Komunikasi"); diff --git a/app/[locale]/(protected)/supervisor/communications/internal/components/table.tsx b/app/[locale]/(protected)/supervisor/communications/collaboration/components/collabroation-table.tsx similarity index 62% rename from app/[locale]/(protected)/supervisor/communications/internal/components/table.tsx rename to app/[locale]/(protected)/supervisor/communications/collaboration/components/collabroation-table.tsx index b8a5f027..3827d234 100644 --- a/app/[locale]/(protected)/supervisor/communications/internal/components/table.tsx +++ b/app/[locale]/(protected)/supervisor/communications/collaboration/components/collabroation-table.tsx @@ -36,22 +36,35 @@ import { TrendingDown, TrendingUp, } from "lucide-react"; -import { cn } from "@/lib/utils"; +import { cn, getCookiesDecrypt } from "@/lib/utils"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, + DropdownMenuRadioGroup, + DropdownMenuRadioItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Input } from "@/components/ui/input"; import { InputGroup, InputGroupText } from "@/components/ui/input-group"; +import { paginationBlog } from "@/service/blog/blog"; +import { ticketingPagination } from "@/service/ticketing/ticketing"; import { Badge } from "@/components/ui/badge"; import { useRouter, useSearchParams } from "next/navigation"; import TablePagination from "@/components/table/table-pagination"; -import { getFaqList } from "@/service/master/faq"; -import columns from "./column"; +import columns from "./columns"; +import { + listDataAudio, + listDataImage, + listDataVideo, +} from "@/service/content/content"; +import { + getTicketingCollaborationPagination, + getTicketingEscalationPagination, + listTicketingInternal, +} from "@/service/communication/communication"; -const FaqTable = () => { +const CollaborationSpvTable = () => { const router = useRouter(); const searchParams = useSearchParams(); @@ -64,13 +77,17 @@ const FaqTable = () => { const [columnVisibility, setColumnVisibility] = React.useState({}); const [rowSelection, setRowSelection] = React.useState({}); + const [showData, setShowData] = React.useState("10"); + const [pagination, setPagination] = React.useState({ pageIndex: 0, - pageSize: 10, + pageSize: Number(showData), }); const [page, setPage] = React.useState(1); const [totalPage, setTotalPage] = React.useState(1); - const [limit, setLimit] = React.useState(10); + const [search, setSearch] = React.useState(""); + + const roleId = getCookiesDecrypt("urie"); const table = useReactTable({ data: dataTable, @@ -94,62 +111,99 @@ const FaqTable = () => { }); React.useEffect(() => { - const pageFromUrl = searchParams?.get('page'); + const pageFromUrl = searchParams?.get("page"); if (pageFromUrl) { setPage(Number(pageFromUrl)); } - }, [searchParams]); + }, [searchParams]); React.useEffect(() => { fetchData(); - }, [page, limit]); + }, [page, showData]); + + let typingTimer: any; + const doneTypingInterval = 1500; + + const handleKeyUp = () => { + clearTimeout(typingTimer); + typingTimer = setTimeout(doneTyping, doneTypingInterval); + }; + + const handleKeyDown = () => { + clearTimeout(typingTimer); + }; + + async function doneTyping() { + fetchData(); + } async function fetchData() { try { - const res = await getFaqList(); - const contentData = res?.data?.data; + const res = await getTicketingCollaborationPagination( + page - 1, + showData, + search + ); + const data = res?.data?.data; + const contentData = data?.content; contentData.forEach((item: any, index: number) => { - item.no = (page - 1) * limit + index + 1; + item.no = (page - 1) * Number(showData) + index + 1; }); - console.log("contentData : ", contentData); - setDataTable(contentData); - setTotalData(contentData?.totalElements || contentData?.length); - setTotalPage(contentData?.totalPages || 1); + setTotalData(data?.totalElements); + setTotalPage(data?.totalPages); } catch (error) { console.error("Error fetching tasks:", error); } } - return (
-
-
+
+
setSearch(e.target.value)} + onKeyDown={handleKeyDown} + onKeyUp={handleKeyUp} />
-
- ) => - table.getColumn("status")?.setFilterValue(event.target.value) - } - className="max-w-sm " - /> -
+ + + + + + + + 1 - 10 Data + + + 1 - 20 Data + + + 1 - 25 Data + + + 1 - 50 Data + + + +
+ {table.getHeaderGroups().map((headerGroup) => ( @@ -191,9 +245,13 @@ const FaqTable = () => { )}
- +
); }; -export default FaqTable; +export default CollaborationSpvTable; diff --git a/app/[locale]/(protected)/supervisor/communications/collaboration/components/column.tsx b/app/[locale]/(protected)/supervisor/communications/collaboration/components/column.tsx deleted file mode 100644 index ee7f653b..00000000 --- a/app/[locale]/(protected)/supervisor/communications/collaboration/components/column.tsx +++ /dev/null @@ -1,76 +0,0 @@ - -import * as React from "react"; -import { - ColumnDef, -} from "@tanstack/react-table"; - -import { - Eye, - MoreVertical, - SquarePen, - Trash2, -} from "lucide-react"; -import { cn } from "@/lib/utils"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuTrigger, - DropdownMenuItem, -} from "@/components/ui/dropdown-menu"; -import { Button } from "@/components/ui/button"; -import { Badge } from "@/components/ui/badge"; - -const columns: ColumnDef[] = [ - { - accessorKey: "no", - header: "No", - cell: ({ row }) => {row.getValue("no")}, - }, - { - accessorKey: "question", - header: "Question", - cell: ({ row }) => {row.getValue("question")}, - }, - { - accessorKey: "answer", - header: "Answer", - cell: ({ row }) => {row.getValue("answer")}, - }, - { - id: "actions", - accessorKey: "action", - header: "Actions", - enableHiding: false, - cell: ({ row }) => { - return ( - - - - - - - - View - - - - Edit - - - - Delete - - - - ); - }, - }, -]; - -export default columns; \ No newline at end of file diff --git a/app/[locale]/(protected)/supervisor/communications/collaboration/components/columns.tsx b/app/[locale]/(protected)/supervisor/communications/collaboration/components/columns.tsx new file mode 100644 index 00000000..bf46ca80 --- /dev/null +++ b/app/[locale]/(protected)/supervisor/communications/collaboration/components/columns.tsx @@ -0,0 +1,114 @@ +import * as React from "react"; +import { ColumnDef } from "@tanstack/react-table"; + +import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react"; +import { cn } from "@/lib/utils"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuTrigger, + DropdownMenuItem, +} from "@/components/ui/dropdown-menu"; +import { Button } from "@/components/ui/button"; +import { Badge } from "@/components/ui/badge"; +import { format } from "date-fns"; +import { Link, useRouter } from "@/i18n/routing"; + +const columns: ColumnDef[] = [ + { + accessorKey: "no", + header: "Nos", + cell: ({ row }) => {row.getValue("no")}, + }, + { + accessorKey: "title", + header: "Pertanyaan", + cell: ({ row }) => ( + {row.getValue("title")} + ), + }, + { + accessorKey: "commentFromUserName", + header: "CreateBy", + cell: ({ row }) => ( + {row.getValue("commentFromUserName")} + ), + }, + { + accessorKey: "Type", + header: "Channel", + cell: ({ row }) => { + const type = row.original.type; + return {type?.name || "N/A"}; + }, + }, + { + accessorKey: "createdAt", + header: "Waktu", + cell: ({ row }) => { + const createdAt = row.getValue("createdAt") as + | string + | number + | undefined; + + const formattedDate = + createdAt && !isNaN(new Date(createdAt).getTime()) + ? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss") + : "-"; + return {formattedDate}; + }, + }, + { + accessorKey: "isActive", + header: "Status", + cell: ({ row }) => { + const isActive = row.getValue("isActive") as boolean; // Ambil nilai isActive + const status = isActive ? "Open" : "Closed"; // Tentukan teks berdasarkan isActive + const statusStyles = isActive + ? "bg-green-100 text-green-600" // Gaya untuk "Open" + : "bg-red-100 text-red-600"; // Gaya untuk "Closed" + + return ( + {status} + ); + }, + }, + + { + id: "actions", + accessorKey: "action", + header: "Actions", + enableHiding: false, + cell: ({ row }) => { + const router = useRouter(); + return ( + + + + + + + router.push( + `/supervisor/communications/forward/detail/${row.original.id}` + ) + } + className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none items-center" + > + + Detail + + + + ); + }, + }, +]; + +export default columns; diff --git a/app/[locale]/(protected)/supervisor/communications/collaboration/create/page.tsx b/app/[locale]/(protected)/supervisor/communications/collaboration/create/page.tsx new file mode 100644 index 00000000..259779ac --- /dev/null +++ b/app/[locale]/(protected)/supervisor/communications/collaboration/create/page.tsx @@ -0,0 +1,15 @@ +import SiteBreadcrumb from "@/components/site-breadcrumb"; +import FormCollaboration from "@/components/form/communication/collaboration-form"; + +const CollaborationCreatePage = () => { + return ( +
+ +
+ +
+
+ ); +}; + +export default CollaborationCreatePage; diff --git a/app/[locale]/(protected)/supervisor/communications/collaboration/detail/[id]/component/users-card.tsx b/app/[locale]/(protected)/supervisor/communications/collaboration/detail/[id]/component/users-card.tsx new file mode 100644 index 00000000..53c2db0c --- /dev/null +++ b/app/[locale]/(protected)/supervisor/communications/collaboration/detail/[id]/component/users-card.tsx @@ -0,0 +1,143 @@ +"use client"; +import { Button } from "@/components/ui/button"; +import Select, { MultiValue } from "react-select"; + +import { Icon } from "@iconify/react/dist/iconify.js"; +import { useEffect, useState } from "react"; +import { Separator } from "@/components/ui/separator"; +import { + getCuratorUser, + saveCollaborationTeams, +} from "@/service/communication/communication"; +import Swal from "sweetalert2"; +import withReactContent from "sweetalert2-react-content"; +import { close, loading } from "@/config/swal"; +import { useParams } from "next/navigation"; +import { useToast } from "@/components/ui/use-toast"; +import { stringify } from "querystring"; + +const assigneeOptions = [ + { value: "mahedi", label: "Mahedi Amin", image: "/images/avatar/av-1.svg" }, + { value: "sovo", label: "Sovo Haldar", image: "/images/avatar/av-2.svg" }, + { + value: "rakibul", + label: "Rakibul Islam", + image: "/images/avatar/av-3.svg", + }, + { value: "pritom", label: "Pritom Miha", image: "/images/avatar/av-4.svg" }, +]; +export default function UsersCard(props: { team: any; fetchData: () => void }) { + const params = useParams(); + const id = params?.id; + const [openSearch, setOpenSearch] = useState(false); + const [selectedUsers, setSelectedUsers] = useState([]); + const [allUser, setAllUser] = useState([]); + const MySwal = withReactContent(Swal); + const { toast } = useToast(); + + useEffect(() => { + async function getUser() { + const res = await getCuratorUser(); + + if (res?.data !== null) { + const rawUser = res?.data?.data?.content; + const optionArr: any = []; + + rawUser.map((option: any) => { + optionArr.push({ + id: option.id, + label: option.username, + value: option.id, + }); + }); + + setAllUser(optionArr); + } + } + getUser(); + }, []); + + const inviteHandle = () => { + MySwal.fire({ + title: "Undang Pengguna Ke Kolom Diskusi?", + text: "", + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#d33", + confirmButtonColor: "#3085d6", + confirmButtonText: "Simpan", + }).then((result) => { + if (result.isConfirmed) { + inviteUser(); + } + }); + }; + + async function inviteUser() { + const userId: any = []; + + selectedUsers?.map((user: any) => { + userId.push(user.id); + }); + loading(); + const res = await saveCollaborationTeams(String(id), userId); + + if (res?.error) { + toast({ title: stringify(res?.message) }); + return false; + } + close(); + + toast({ title: "Berhasil menambahkan user" }); + props.fetchData(); + } + + return ( +
+
+
+

Kolaborator

+

+ {props?.team?.length} +

+
+ setOpenSearch(!openSearch)}> + + +
+ {openSearch && ( +
+