import { Divider, Select, Switch, Tooltip } from "antd"; const { Option } = Select; import Modal from "antd/lib/modal/Modal"; import { useEffect, useState } from "react"; import toast from "react-hot-toast"; import { useAuth } from "../../contexts/authContext"; import { ShowModalType, useKeyboardContext, } from "../../contexts/keyboardContext"; import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; import Link, { LinkType } from "../../models/link"; import { SendService } from "../../services/sendService"; import LinkIcon from "../LinkIcon"; const sendService = new SendService(); export default function CreateOrUpdateLink() { const { currUser } = useAuth(); const { pastedLink, handleModalType, showModalType } = useKeyboardContext(); const { teamUsers, team } = useTeamDashboardContext(); useEffect(() => { if (pastedLink) { setLink(pastedLink ?? ""); } }, [pastedLink]); function closeModal() { handleModalType(ShowModalType.na); } function handleSelectRecipients(value) { // passed in array of selections...userIds setRecipientsSelected(value); console.log(value); } function handleSelectRecipientMode(isChecked) { // clear the list of recipients if team selected if (isChecked) { setRecipientsSelected([]); setIsTeamLink(true); } else { setRecipientsSelected([]); setIsTeamLink(false); } } async function handleSubmitLink() { if (!link || !name) { toast.error("Please add a valid link and name"); return; } if ( !isTeamLink && (!recipientsSelected || recipientsSelected.length == 0) ) { toast.error( "Please select members or send it to the team with the toggle" ); return; } // if it's a team link, make sure recipients is null ... but the model should handle this for us? try { const newLink = new Link( name, description, link, team.id, recipientsSelected, currUser.uid ); handleModalType(ShowModalType.na); // send to database await sendService.sendLink(newLink); resetForm(); toast.success("link sent"); } catch (error) { toast.error("Something went wrong in sending the link."); console.log(error); } } function resetForm() { setLink(""); setName(""); setDescription(""); setShowMoreDetails(false); setIsTeamLink(true); setRecipientsSelected([]); } const [link, setLink] = useState(""); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [showMoreDetails, setShowMoreDetails] = useState(false); const [isTeamLink, setIsTeamLink] = useState(true); const [recipientsSelected, setRecipientsSelected] = useState([]); return (
Link Please make sure this is valid for others to access. {/* icon and link input */} setLink(e.target.value)} /> Name Make sure this makes sense to who you are sending it to. setName(e.target.value)} /> Recipients Choose team or individual recipients Team} unCheckedChildren={Members} /> {/* select team members to send to */} {!isTeamLink ? ( ) : ( <> )} {showMoreDetails ? ( <> Description Optional - Add any pointers about this file. setDescription(e.target.value)} /> ) : ( )}
); }