QUDO-273
This commit is contained in:
parent
576b129cc9
commit
19f1a59feb
|
|
@ -15,6 +15,7 @@ import { close, loading } from "@/config/swal";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { stringify } from "querystring";
|
import { stringify } from "querystring";
|
||||||
|
import { useRouter } from "@/i18n/routing";
|
||||||
|
|
||||||
const assigneeOptions = [
|
const assigneeOptions = [
|
||||||
{ value: "mahedi", label: "Mahedi Amin", image: "/images/avatar/av-1.svg" },
|
{ value: "mahedi", label: "Mahedi Amin", image: "/images/avatar/av-1.svg" },
|
||||||
|
|
@ -26,8 +27,15 @@ const assigneeOptions = [
|
||||||
},
|
},
|
||||||
{ value: "pritom", label: "Pritom Miha", image: "/images/avatar/av-4.svg" },
|
{ value: "pritom", label: "Pritom Miha", image: "/images/avatar/av-4.svg" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
type UserOption = {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
export default function UsersCard(props: { team: any; fetchData: () => void }) {
|
export default function UsersCard(props: { team: any; fetchData: () => void }) {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
|
const router = useRouter();
|
||||||
const id = params?.id;
|
const id = params?.id;
|
||||||
const [openSearch, setOpenSearch] = useState(false);
|
const [openSearch, setOpenSearch] = useState(false);
|
||||||
const [selectedUsers, setSelectedUsers] = useState<any>([]);
|
const [selectedUsers, setSelectedUsers] = useState<any>([]);
|
||||||
|
|
@ -60,36 +68,56 @@ export default function UsersCard(props: { team: any; fetchData: () => void }) {
|
||||||
const inviteHandle = () => {
|
const inviteHandle = () => {
|
||||||
MySwal.fire({
|
MySwal.fire({
|
||||||
title: "Undang Pengguna Ke Kolom Diskusi?",
|
title: "Undang Pengguna Ke Kolom Diskusi?",
|
||||||
text: "",
|
|
||||||
icon: "warning",
|
icon: "warning",
|
||||||
showCancelButton: true,
|
showCancelButton: true,
|
||||||
cancelButtonColor: "#d33",
|
|
||||||
confirmButtonColor: "#3085d6",
|
confirmButtonColor: "#3085d6",
|
||||||
|
cancelButtonColor: "#d33",
|
||||||
confirmButtonText: "Simpan",
|
confirmButtonText: "Simpan",
|
||||||
}).then((result) => {
|
}).then(async (result) => {
|
||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
inviteUser();
|
const success = await inviteUser();
|
||||||
|
if (!success) {
|
||||||
|
await MySwal.fire({
|
||||||
|
title: "Gagal mengundang pengguna!",
|
||||||
|
text: "Silakan coba lagi.",
|
||||||
|
icon: "error",
|
||||||
|
confirmButtonText: "OK",
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async function inviteUser() {
|
async function inviteUser(): Promise<boolean> {
|
||||||
const userId: any = [];
|
try {
|
||||||
|
if (!selectedUsers || selectedUsers.length === 0) {
|
||||||
|
toast({ title: "Pilih user terlebih dahulu" });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
selectedUsers?.map((user: any) => {
|
const userIds = selectedUsers.map((user: any) => user.value);
|
||||||
userId.push(user.id);
|
loading();
|
||||||
});
|
|
||||||
loading();
|
|
||||||
const res = await saveCollaborationTeams(String(id), userId);
|
|
||||||
|
|
||||||
if (res?.error) {
|
const res = await saveCollaborationTeams(String(id), userIds);
|
||||||
toast({ title: stringify(res?.message) });
|
|
||||||
|
close();
|
||||||
|
|
||||||
|
if (res?.error) {
|
||||||
|
toast({ title: String(res?.message) });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({ title: "Berhasil menambahkan user" });
|
||||||
|
|
||||||
|
props?.fetchData?.();
|
||||||
|
window.location.reload();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
close();
|
||||||
|
toast({ title: "Terjadi kesalahan, coba lagi." });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
close();
|
|
||||||
|
|
||||||
toast({ title: "Berhasil menambahkan user" });
|
|
||||||
props.fetchData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -108,17 +136,17 @@ export default function UsersCard(props: { team: any; fetchData: () => void }) {
|
||||||
{openSearch && (
|
{openSearch && (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<Select
|
<Select
|
||||||
className="react-select my-2 transition-shadow"
|
|
||||||
classNamePrefix="select"
|
|
||||||
options={allUser}
|
|
||||||
isMulti
|
isMulti
|
||||||
onChange={(selectedOption) => setSelectedUsers(selectedOption)}
|
options={allUser}
|
||||||
|
value={selectedUsers}
|
||||||
|
onChange={(selected) => setSelectedUsers(selected as UserOption[])}
|
||||||
placeholder="Select users"
|
placeholder="Select users"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{selectedUsers?.length > 0 && (
|
{selectedUsers?.length > 0 && (
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end mt-2">
|
||||||
<Button color="primary" size="sm" onClick={inviteHandle}>
|
<Button color="primary" size="sm" onClick={inviteHandle}>
|
||||||
Invie
|
Invite
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue