From fcbbe28a3cdf2663506877758f7eb4ff35cfeddb Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Fri, 15 Jan 2021 13:49:20 +0200 Subject: [PATCH] fix profile update modal --- components/t/TeamProfileModal.tsx | 165 ++++++++++++++---------------- pages/t/[team].tsx | 18 +++- 2 files changed, 91 insertions(+), 92 deletions(-) diff --git a/components/t/TeamProfileModal.tsx b/components/t/TeamProfileModal.tsx index a1cd71117..02403a3eb 100644 --- a/components/t/TeamProfileModal.tsx +++ b/components/t/TeamProfileModal.tsx @@ -32,20 +32,19 @@ import { GetTeamData } from "prisma/queries/getTeam"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { FaTwitter } from "react-icons/fa"; -import { FiEdit } from "react-icons/fi"; import { mutate } from "swr"; import * as z from "zod"; interface Props { team: NonNullable; + closeModal: () => void; } type FormData = z.infer; -const TeamProfileModal: React.FC = ({ team }) => { +const TeamProfileModal: React.FC = ({ team, closeModal }) => { const { i18n } = useLingui(); const toast = useToast(); - const [isOpen, setIsOpen] = useState(false); const [sending, setSending] = useState(false); const { handleSubmit, errors, register, watch } = useForm({ @@ -57,7 +56,7 @@ const TeamProfileModal: React.FC = ({ team }) => { const watchRecruitingPost = watch("recruitingPost", team.recruitingPost); const onSubmit = async (formData: FormData) => { - const modifiedData: FormData = {}; + const modifiedData: FormData = formData; for (const [key, value] of Object.entries(formData)) { if (value === "" || value === undefined) { @@ -76,99 +75,85 @@ const TeamProfileModal: React.FC = ({ team }) => { toast(getToastOptions(t`Team profile updated`, "success")); - setIsOpen(false); + closeModal(); }; return ( - <> - - {isOpen && ( - setIsOpen(false)} - size="xl" - closeOnOverlayClick={false} - > - - - - Editing team profile - - -
- - - - {" "} - Twitter name - - - - - - - - Twitter is also used to get the team's avatar. - - - - {errors.twitterName?.message} - - - - + + + + Editing team profile + + + + + + + {" "} + Twitter name + + + + + + + Twitter is also used to get the team's avatar. + + + {errors.twitterName?.message} + + - - + )} + /> - - - - - - - -
- )} - + + + + + + + + + + + ); }; diff --git a/pages/t/[team].tsx b/pages/t/[team].tsx index 0e3d2d556..70094c7ce 100644 --- a/pages/t/[team].tsx +++ b/pages/t/[team].tsx @@ -37,6 +37,7 @@ import Image from "next/image"; import { getTeam, GetTeamData } from "prisma/queries/getTeam"; import { Fragment, useEffect, useState } from "react"; import { FaTwitter } from "react-icons/fa"; +import { FiEdit } from "react-icons/fi"; import useSWR, { mutate } from "swr"; interface Props { @@ -106,6 +107,7 @@ const TeamPage: React.FC = (props) => { const team = data!; const [sending, setSending] = useState(false); + const [profileModalIsOpen, setProfileModalIsOpen] = useState(false); const [user] = useUser(); const toast = useToast(); @@ -133,6 +135,12 @@ const TeamPage: React.FC = (props) => { return ( + {profileModalIsOpen && ( + setProfileModalIsOpen(false)} + /> + )} {team.twitterName && ( @@ -159,7 +167,7 @@ const TeamPage: React.FC = (props) => { {teamXPData.teamXP !== "2000" && ( -
+
{teamXPData.teamXP}
@@ -210,7 +218,13 @@ const TeamPage: React.FC = (props) => {
- +
)}