diff --git a/packages/web/components/Modals/CreateOrUpdateLink.tsx b/packages/web/components/Modals/CreateOrUpdateLink.tsx deleted file mode 100644 index 2e444c6..0000000 --- a/packages/web/components/Modals/CreateOrUpdateLink.tsx +++ /dev/null @@ -1,231 +0,0 @@ -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)} - /> - - - ) : ( - - )} -
-
- ); -} diff --git a/packages/web/components/Modals/CreateOrUpdateRoom.tsx b/packages/web/components/Modals/CreateOrUpdateRoom.tsx deleted file mode 100644 index 4082bf0..0000000 --- a/packages/web/components/Modals/CreateOrUpdateRoom.tsx +++ /dev/null @@ -1,532 +0,0 @@ -import { - DatePicker, - Divider, - Modal, - Radio, - Select, - Switch, - TimePicker, - Tooltip, -} from "antd"; -import { Timestamp } from "firebase/firestore"; -import moment from "moment"; -import React, { useEffect, useState } from "react"; -import toast from "react-hot-toast"; -import { GlobalHotKeys, KeyMap } from "react-hotkeys"; -import { useAuth } from "../../contexts/authContext"; -import { - ShowModalType, - useKeyboardContext, -} from "../../contexts/keyboardContext"; -import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; -import Room, { RoomStatus, RoomType } from "../../models/room"; -import { User } from "../../models/user"; -import RoomService from "../../services/roomService"; - -const { Option } = Select; - -const roomService = new RoomService(); - -interface IModalProps { - show: boolean; - updateRoom: Room; - handleClose: Function; -} - -export default function CreateOrUpdateRoomModal(props: IModalProps) { - const { currUser } = useAuth(); - const { teamUsers, team, user } = useTeamDashboardContext(); - const { pastedLink, handleModalType, showModalType } = useKeyboardContext(); - - // handle when we want to update a room and props changes - // prefill with existing stuff - useEffect(() => { - console.log("change in props"); - - if (props.updateRoom) { - setRoomLink(props.updateRoom.link); - setRoomName(props.updateRoom.name); - setRoomDescription(props.updateRoom.description); - if (props.updateRoom.attachments && props.updateRoom.attachments[0]) { - setRoomAttachment(props.updateRoom.attachments[0]); - } - setMembersSelected(props.updateRoom.members); - setRoomType(props.updateRoom.type); - setRoomAppxDateTime(props.updateRoom.approximateDateTime); - - if (props.updateRoom.scheduledDateTime) { - const convertedToMoment = moment( - props.updateRoom.scheduledDateTime.toDate() - ); - setDateTimePicker(convertedToMoment); - } - } else { - // update state when user does ctrl + v - resetForm(); - } - }, [props.updateRoom]); - - // update state when user does ctrl + v - useEffect(() => { - // todo: check if link is valid google meet link? again? - console.log("updated link!!!!!"); - setRoomLink(pastedLink); - }, [pastedLink]); - - const handleCloseModal = () => { - resetForm(); - - props.handleClose(); - }; - - const handleSubmit = async () => { - // make sure link, room, and type are selected - if (!roomName) { - toast.error("Please fill in room link and name."); - return; - } - if (!roomLink && !hasGSuite) { - toast.error("must provide room link if you don't have a GSuite"); - return; - } - - try { - const newRoom = new Room(); - - if (roomAttachment) { - newRoom.attachments = [roomAttachment]; - } - - if (hasGSuite) { - // create google meet link based on the room name without spaces - var slugName = - user.firstName + - "-" + - "room" + - moment(new Date()).format("dddddohmma"); - slugName = slugName.replace(/\s/g, "-"); - - const autoLink = - "https://accounts.google.com/AccountChooser/signinchooser?continue=https://g.co/meet/" + - slugName; - - newRoom.link = autoLink; - } else { - newRoom.link = roomLink; - } - - if (roomType == RoomType.now) { - // make sure approximate time isn't selected - newRoom.approximateDateTime = null; - newRoom.status = RoomStatus.live; - - // automatically add me to the room - newRoom.membersInRoom = []; - - // navigate to the new room automatically - // window.open(roomLink, "_blank"); - } else if (roomType == RoomType.scheduled) { - // make sure that either appx or time picker is selected, not both - if (!dateTimePicker) { - toast.error("Please select a date and time!"); - return; - } - - newRoom.approximateDateTime = null; - - newRoom.scheduledDateTime = Timestamp.fromDate(dateTimePicker.toDate()); - } else if (roomType == RoomType.recurring) { - // clear the field for the time picker if they ever selected that - newRoom.scheduledDateTime = null; - - newRoom.approximateDateTime = roomAppxDateTime; - } - - newRoom.members = [...membersSelected]; // add currUser to the list of "people" - newRoom.type = roomType; - newRoom.description = roomDescription; - newRoom.name = roomName; - newRoom.createdByUserId = currUser.uid; - newRoom.teamId = team.id; - - if (props.updateRoom) { - newRoom.id = props.updateRoom.id; - newRoom.membersInRoom = props.updateRoom.membersInRoom; - toast.success("updated room"); - } else { - toast.success("created room"); - } - - console.log(newRoom); - - handleModalType(ShowModalType.na); - - await roomService.createOrUpdateRoom(newRoom); - - resetForm(); - } catch (error) { - toast.error("problem creating/updating room"); - console.log(error); - } - }; - - function resetForm() { - setRoomLink(""); - setRoomName( - user.firstName + - "'s Room - " + - moment(new Date()).format("dddd do h:mm a") - ); - setRoomDescription(""); - setMembersSelected([currUser.uid] as string[]); - setRoomAttachment(""); - setRoomAppxDateTime(""); - setRoomType(RoomType.now); - - setDateTimePicker(null); - - setShowMoreDetails(false); - - sethasGSuite(true); - } - - const [roomLink, setRoomLink] = useState(pastedLink ?? ""); - const [roomName, setRoomName] = useState( - user.firstName + "'s Room - " + moment(new Date()).format("dddd do h:mm a") - ); - const [roomDescription, setRoomDescription] = useState(""); - - const [roomAttachment, setRoomAttachment] = useState(""); - const [membersSelected, setMembersSelected] = useState([ - currUser.uid, - ]); - - const [roomType, setRoomType] = useState(RoomType.now); - const [roomAppxDateTime, setRoomAppxDateTime] = useState(""); // for certain room types - const [dateTimePicker, setDateTimePicker] = useState(null); - - const [showMoreDetails, setShowMoreDetails] = useState(false); - const [hasGSuite, sethasGSuite] = useState(true); - - function handleSelectMember(value) { - // passed in array of selections...userIds - - setMembersSelected(value); - - console.log(value); - } - - function handleDateTimePickerChange(time) { - console.log(time); - - setRoomAppxDateTime(""); - - setDateTimePicker(time); - } - - const allUsersForSelection: User[] = [...teamUsers, user]; - - const MemberSelection = () => { - return ( - - ); - }; - - async function createRoomNow() { - console.log("creating room"); - - // reset form for the right values to be in there - resetForm(); - - // submit form - // handleSubmit().then((res) => console.log(res)); - - const newRoom = new Room(); - - // create google meet link based on the room name without spaces - var slugName = - user.firstName + "-" + "room" + moment(new Date()).format("dddddohmma"); - slugName = slugName.replace(/\s/g, "-"); - - const autoLink = - "https://accounts.google.com/AccountChooser/signinchooser?continue=https://g.co/meet/" + - slugName; - - newRoom.link = autoLink; - newRoom.status = RoomStatus.empty; - newRoom.membersInRoom = []; - newRoom.approximateDateTime = null; - - newRoom.members = [currUser.uid]; // add currUser to the list of "people" - newRoom.type = RoomType.now; - newRoom.name = roomName; - newRoom.createdByUserId = currUser.uid; - newRoom.teamId = team.id; - - console.log(newRoom); - - handleModalType(ShowModalType.na); - - await roomService.createOrUpdateRoom(newRoom); - - resetForm(); - - toast.success("created room"); - } - - const keyMap: KeyMap = { - CREATE_ROOM_NOW: { - name: "create room now", - sequence: "q", - action: "keyup", - }, - }; - const handlers = { - CREATE_ROOM_NOW: createRoomNow, - }; - - return ( - <> - - - -
- {hasGSuite ? ( - - Link - - We'll create a link for you. Don't have a GSuite?{" "} - - - - ) : ( - - Link - {roomLink ? ( - - Please make sure this is valid so that your team can join - properly. - - ) : ( - - - Click here to create one - {" "} - and then come back and paste the link for your team.{" "} - - - )} - - setRoomLink(e.target.value)} - /> - - )} - - - Room Name - - Be specific enough, everyone down the hall will see this. - - setRoomName(e.target.value)} - /> - - - {/* room type selection */} - - Type - - setRoomType(event.target.value)} - > - {RoomType.now} - - {RoomType.scheduled} - - - {RoomType.recurring} - - - - {roomType == RoomType.recurring ? ( - - - Approximate Slot - - Sometimes you don't have a specific time or want to - propose a rough period. - - setRoomAppxDateTime(e.target.value)} - /> - - - ) : ( - <> - )} - - {roomType == RoomType.scheduled ? ( - - Specific Time - {/* */} - - - - ) : ( - <> - )} - - - {/* people selection */} - - - People - {/* team or personal */} - - - - Visible} - unCheckedChildren={Private} - /> - - - Team sees this room. - - - - - - Optional - Add any mandatory attendees you want or just tell them - later. - - {MemberSelection()} - - - {showMoreDetails ? ( - <> - - - - - - Agenda - - Optional - -