import { gql, useMutation } from "@apollo/client"; import { Box, Button, FormControl, FormHelperText, FormLabel, Input, Modal, ModalBody, ModalCloseButton, ModalContent, ModalHeader, ModalOverlay, Tab, TabList, TabPanel, TabPanels, Tabs, } from "@chakra-ui/react"; import React from "react"; import { ErrorMessage, getGraphQLErrorMessage } from "../util"; export default function LoginModal({ isOpen, onClose }) { return ( Welcome back to Dress to Impress! ✨ Log in Create account onClose()} /> ); } function LoginForm({ onSuccess }) { const [username, setUsername] = React.useState(""); const [password, setPassword] = React.useState(""); const [ sendLoginMutation, { loading, error, data, called, reset }, ] = useMutation(gql` mutation LoginForm_Login($username: String!, $password: String!) { login(username: $username, password: $password) { id username } } `); return (
{ e.preventDefault(); sendLoginMutation({ variables: { username, password }, }) .then(({ data }) => { if (data?.login != null) { onSuccess(); } }) .catch((e) => {}); // handled in error UI }} > DTI Username { setUsername(e.target.value); reset(); }} /> This is separate from your Neopets.com account. DTI Password { setPassword(e.target.value); reset(); }} /> Careful, never enter your Neopets password on another site! {error && ( Oops, login failed: "{getGraphQLErrorMessage(error)}". Try again? )} {called && !loading && !error && data?.login == null && ( We couldn't find a match for that username and password. Try again? )} ); } function CreateAccountForm() { const onSubmit = (e) => { e.preventDefault(); alert("TODO: Create account!"); }; return (
DTI Username This will be separate from your Neopets.com account. DTI Password Careful, never use your Neopets password for another site! Confirm DTI Password One more time, to make sure! Email address We'll use this in the future if you need to reset your password, or for us to contact you about your account. We won't sell this address, and we won't send marketing-y emails. ); }