From 7eabc4a7beeac26005c826ec57ed885c4b0b4d48 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sun, 22 Nov 2020 16:59:20 +0200 Subject: [PATCH] build modal initial --- components/common/MySelect.tsx | 27 +- components/u/BuildModal.tsx | 274 ++++ lib/lists/gear.ts | 1184 +++++++-------- lib/validators/build.ts | 11 +- locale/de/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/el/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/en/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/es/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/fr/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/it/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/ja/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/ko/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/nl/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/pt/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/ru/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/sv/messages.po | 2485 +++++++++++++++++++++++++++++++- locale/zh/messages.po | 2485 +++++++++++++++++++++++++++++++- pages/u/[identifier].tsx | 21 +- 18 files changed, 32962 insertions(+), 860 deletions(-) create mode 100644 components/u/BuildModal.tsx diff --git a/components/common/MySelect.tsx b/components/common/MySelect.tsx index ce34951d4..6a3d14dfa 100644 --- a/components/common/MySelect.tsx +++ b/components/common/MySelect.tsx @@ -14,20 +14,17 @@ const MySelect: React.FC = ({ placeholder, children, name, -}) => { - console.log({ value }); - return ( - - ); -}; +}) => ( + +); export default MySelect; diff --git a/components/u/BuildModal.tsx b/components/u/BuildModal.tsx new file mode 100644 index 000000000..8ead674ed --- /dev/null +++ b/components/u/BuildModal.tsx @@ -0,0 +1,274 @@ +import { + Button, + Checkbox, + CheckboxGroup, + FormControl, + FormErrorMessage, + FormHelperText, + FormLabel, + Input, + Modal, + ModalBody, + ModalCloseButton, + ModalContent, + ModalFooter, + ModalHeader, + ModalOverlay, + Stack, + Textarea, + useToast, +} from "@chakra-ui/react"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { t, Trans } from "@lingui/macro"; +import { useLingui } from "@lingui/react"; +import MySelect from "components/common/MySelect"; +import WeaponSelector from "components/common/WeaponSelector"; +import { gear } from "lib/lists/gear"; +import { Unpacked } from "lib/types"; +import { + buildSchema, + DESCRIPTION_CHARACTER_LIMIT, + TITLE_CHARACTER_LIMIT, +} from "lib/validators/build"; +import { GetBuildsByUserData } from "prisma/queries/getBuildsByUser"; +import { Fragment } from "react"; +import { Controller, useForm } from "react-hook-form"; +import * as z from "zod"; + +interface Props { + onClose: () => void; + build?: Unpacked>; +} + +type FormData = z.infer; + +const BuildModal: React.FC = ({ onClose, build }) => { + const { i18n } = useLingui(); + + const { handleSubmit, errors, register, watch, control } = useForm({ + resolver: zodResolver(buildSchema), + defaultValues: build, + }); + + const watchTitle = watch("title", build?.title ?? ""); + const watchDescription = watch("description", build?.description ?? ""); + + const toast = useToast(); + + // const onSubmit = async (formData: FormData) => { + + // for (const [key, value] of Object.entries(mutationData)) { + // if (value === "" || value === undefined) { + // const typedKey = key as keyof Omit; + // mutationData[typedKey] = null; + // } + // } + + // const success = await sendData("PUT", "/api/me/profile", mutationData); + // if (!success) return; + + // mutate(`/api/users/${user.id}`); + + // toast(getToastOptions(build ? t`Profile updated` : t`Profile updated`, "success")); + // onClose(); + // }; + const onSubmit = async (formData: FormData) => console.log({ formData }); + + return ( + + + + + {build ? ( + Editing build + ) : ( + Adding a new build + )} + + +
+ + + Weapon + + ( + + )} + /> + + + + Title + + + + {watchTitle!.length}/{TITLE_CHARACTER_LIMIT} + + {errors.title?.message} + + + + + Description + +