diff --git a/frontend-react/src/components/elements/Modal.tsx b/frontend-react/src/components/elements/Modal.tsx index 346502660..08cec9a5b 100644 --- a/frontend-react/src/components/elements/Modal.tsx +++ b/frontend-react/src/components/elements/Modal.tsx @@ -50,7 +50,7 @@ const Modal: React.FC = ({ children, title, closeModal }) => { alignItems="center" fontSize="24px" fontWeight="black" - mb="1.5em" + mb="0.5em" > {title} {closeModal && ( diff --git a/frontend-react/src/components/elements/TextArea.tsx b/frontend-react/src/components/elements/TextArea.tsx index 264e6b8f7..bafe1c311 100644 --- a/frontend-react/src/components/elements/TextArea.tsx +++ b/frontend-react/src/components/elements/TextArea.tsx @@ -10,6 +10,7 @@ interface TextAreaProps { label?: string limit?: number required?: boolean + height?: string id?: string } @@ -19,6 +20,7 @@ const TextArea: React.FC = ({ label, limit, required, + height, }) => { const { themeColorHex, grayWithShade, darkerBgColor } = useContext( MyThemeContext @@ -35,6 +37,7 @@ const TextArea: React.FC = ({ onChange={handleChange} focusBorderColor={themeColorHex} size="md" + height={height} _hover={{}} background={darkerBgColor} borderColor="#CCCCCC" diff --git a/frontend-react/src/components/freeagents/FAPostModal.tsx b/frontend-react/src/components/freeagents/FAPostModal.tsx new file mode 100644 index 000000000..285a53141 --- /dev/null +++ b/frontend-react/src/components/freeagents/FAPostModal.tsx @@ -0,0 +1,324 @@ +import React, { useState, useContext } from "react" +import Modal from "../elements/Modal" +import { useMutation } from "@apollo/react-hooks" +import { + useToast, + FormControl, + FormLabel, + RadioGroup, + Radio, + Flex, + Box, + FormErrorMessage, + CheckboxGroup, + Checkbox, +} from "@chakra-ui/core" +import MyThemeContext from "../../themeContext" +import TextArea from "../elements/TextArea" +import Button from "../elements/Button" +import { FreeAgentPost } from "../../types" +import { + AddFreeAgentPostVars, + ADD_FREE_AGENT_POST, +} from "../../graphql/mutations/addFreeAgentPost" +import { FREE_AGENT_POSTS } from "../../graphql/queries/freeAgentPosts" +import { UPDATE_FREE_AGENT_POST } from "../../graphql/mutations/updateFreeAgentPost" +import { HIDE_FREE_AGENT_POST } from "../../graphql/mutations/hideFreeAgentPost" +import Alert from "../elements/Alert" + +interface FAPostModalProps { + closeModal: () => void + post?: FreeAgentPost +} + +const FAPostModal: React.FC = ({ closeModal, post }) => { + const [form, setForm] = useState>( + post ? post : {} + ) + const [showErrors, setShowErrors] = useState(false) + const [deleting, setDeleting] = useState(false) + const toast = useToast() + const { themeColor, grayWithShade } = useContext(MyThemeContext) + + const [addFreeAgentPost] = useMutation( + ADD_FREE_AGENT_POST, + { + variables: { ...(form as AddFreeAgentPostVars) }, + onCompleted: data => { + closeModal() + toast({ + description: `Free agent post added`, + position: "top-right", + status: "success", + duration: 10000, + }) + }, + onError: error => { + toast({ + title: "An error occurred", + description: error.message, + position: "top-right", + status: "error", + duration: 10000, + }) + }, + refetchQueries: [{ query: FREE_AGENT_POSTS }], + } + ) + + const [editFreeAgentPost] = useMutation( + UPDATE_FREE_AGENT_POST, + { + variables: { ...(form as AddFreeAgentPostVars) }, + onCompleted: data => { + closeModal() + toast({ + description: `Free agent post edited`, + position: "top-right", + status: "success", + duration: 10000, + }) + }, + onError: error => { + toast({ + title: "An error occurred", + description: error.message, + position: "top-right", + status: "error", + duration: 10000, + }) + }, + refetchQueries: [{ query: FREE_AGENT_POSTS }], + } + ) + + const [hideFreeAgentPost] = useMutation( + HIDE_FREE_AGENT_POST, + { + variables: { ...(form as AddFreeAgentPostVars) }, + onCompleted: data => { + closeModal() + toast({ + description: `Free agent post deleted`, + position: "top-right", + status: "success", + duration: 10000, + }) + }, + onError: error => { + toast({ + title: "An error occurred", + description: error.message, + position: "top-right", + status: "error", + duration: 10000, + }) + }, + refetchQueries: [{ query: FREE_AGENT_POSTS }], + } + ) + + const handleChange = (newValueObject: Partial) => { + setForm({ ...form, ...newValueObject }) + } + + const actionType = post ? "EDIT" : "NEW" + + const handleSubmit = () => { + if ( + form.playstyles?.length === 0 || + !form.can_vc || + (form.past_experience ?? "").length > 100 || + (form.activity ?? "").length > 100 || + (form.looking_for ?? "").length > 100 || + (form.description ?? "").length > 1000 + ) { + setShowErrors(true) + return + } + + if (actionType === "NEW") addFreeAgentPost() + if (actionType === "EDIT") editFreeAgentPost() + } + + return ( + + {actionType === "EDIT" && ( + setDeleting(true)} + > + Delete free agent post + + )} + {deleting && ( + <> + + Note that if you decide to delete your post you need to wait a week + before posting a new one. + + + + + + + + + )} + {actionType === "NEW" && ( + + Profile picture, Discord name, Twitter user, weapon pool and Top 500 + history are automatically synced up with your profile. Also please + note that the post automatically sent to Discord can't be edited + afterwardsso you want to set these before making a post. + + )} + + Playstyles + + handleChange({ + playstyles: value as ("FRONTLINE" | "MIDLINE" | "BACKLINE")[], + }) + } + > + Frontline/Slayer + Midline/Support + Backline/Anchor + + Required field + + + + Can you voice chat? + + handleChange({ + can_vc: value as "YES" | "USUALLY" | "SOMETIMES" | "NO", + }) + } + > + Yes + Usually + Sometimes + No + + Required field + + + 100 + } + mt="1em" + > + + Past competitive experience + +