2020-05-10 00:21:04 -07:00
|
|
|
import React from "react";
|
2020-05-10 00:54:23 -07:00
|
|
|
import { css } from "emotion";
|
|
|
|
import gql from "graphql-tag";
|
2020-08-12 00:37:31 -07:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Button,
|
|
|
|
Flex,
|
2020-10-07 09:48:55 -07:00
|
|
|
IconButton,
|
2020-08-12 00:37:31 -07:00
|
|
|
Input,
|
2020-10-07 09:48:55 -07:00
|
|
|
Textarea,
|
2020-08-12 00:37:31 -07:00
|
|
|
useColorModeValue,
|
|
|
|
useTheme,
|
|
|
|
useToast,
|
|
|
|
} from "@chakra-ui/core";
|
2020-10-07 09:48:55 -07:00
|
|
|
import { CloseIcon } from "@chakra-ui/icons";
|
2020-09-06 18:12:34 -07:00
|
|
|
import { useHistory, useLocation } from "react-router-dom";
|
2020-07-31 23:10:34 -07:00
|
|
|
import { useLazyQuery } from "@apollo/client";
|
2020-05-10 00:21:04 -07:00
|
|
|
|
2020-10-09 08:18:18 -07:00
|
|
|
import { Heading1, useLocalStorage, usePageTitle } from "./util";
|
2020-07-22 22:07:45 -07:00
|
|
|
import OutfitPreview from "./components/OutfitPreview";
|
2020-10-09 08:01:46 -07:00
|
|
|
import SpeciesColorPicker from "./components/SpeciesColorPicker";
|
2020-05-10 00:21:04 -07:00
|
|
|
|
|
|
|
import HomepageSplashImg from "../images/homepage-splash.png";
|
2020-05-23 13:59:56 -07:00
|
|
|
import HomepageSplashImg2x from "../images/homepage-splash@2x.png";
|
2020-10-09 08:01:46 -07:00
|
|
|
import FeedbackXweeImg from "../images/feedback-xwee.png";
|
|
|
|
import FeedbackXweeImg2x from "../images/feedback-xwee@2x.png";
|
2020-05-10 00:21:04 -07:00
|
|
|
|
|
|
|
function HomePage() {
|
2020-09-11 23:53:57 -07:00
|
|
|
usePageTitle(null);
|
2020-07-31 16:57:37 -07:00
|
|
|
useSupportSetup();
|
2020-05-17 23:26:00 -07:00
|
|
|
|
2020-07-22 22:07:45 -07:00
|
|
|
const [previewState, setPreviewState] = React.useState(null);
|
|
|
|
|
2020-05-10 00:21:04 -07:00
|
|
|
return (
|
2020-09-06 18:12:34 -07:00
|
|
|
<Flex direction="column" align="center" textAlign="center" marginTop="8">
|
2020-05-17 23:26:00 -07:00
|
|
|
<Box
|
|
|
|
width="200px"
|
|
|
|
height="200px"
|
2020-07-20 21:32:42 -07:00
|
|
|
borderRadius="lg"
|
2020-05-17 23:26:00 -07:00
|
|
|
boxShadow="md"
|
2020-07-22 22:07:45 -07:00
|
|
|
overflow="hidden"
|
|
|
|
>
|
|
|
|
<OutfitPreview
|
|
|
|
speciesId={previewState?.speciesId}
|
|
|
|
colorId={previewState?.colorId}
|
|
|
|
pose={previewState?.pose}
|
|
|
|
wornItemIds={[]}
|
2020-09-13 04:12:14 -07:00
|
|
|
loadingDelayMs={1500}
|
2020-07-22 22:07:45 -07:00
|
|
|
placeholder={
|
|
|
|
<Box
|
|
|
|
as="img"
|
|
|
|
src={HomepageSplashImg}
|
|
|
|
srcSet={`${HomepageSplashImg} 1x, ${HomepageSplashImg2x} 2x`}
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Box>
|
2020-05-17 23:26:00 -07:00
|
|
|
<Box height="4" />
|
|
|
|
<Heading1>Dress to Impress</Heading1>
|
2020-10-07 07:52:34 -07:00
|
|
|
<Box fontSize="lg" fontStyle="italic" opacity="0.85" role="doc-subtitle">
|
|
|
|
Design and share your Neopets outfits!
|
|
|
|
</Box>
|
2020-05-17 23:26:00 -07:00
|
|
|
<Box height="8" />
|
2020-07-22 22:07:45 -07:00
|
|
|
<StartOutfitForm onChange={setPreviewState} />
|
2020-05-17 23:26:00 -07:00
|
|
|
<Box height="4" />
|
|
|
|
<Box fontStyle="italic" fontSize="sm">
|
|
|
|
or
|
|
|
|
</Box>
|
|
|
|
<Box height="4" />
|
|
|
|
<SubmitPetForm />
|
2020-10-07 09:48:55 -07:00
|
|
|
<Box height="16" />
|
|
|
|
<FeedbackFormSection />
|
2020-05-17 23:26:00 -07:00
|
|
|
</Flex>
|
2020-05-10 00:21:04 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-22 22:07:45 -07:00
|
|
|
function StartOutfitForm({ onChange }) {
|
2020-05-10 00:21:04 -07:00
|
|
|
const history = useHistory();
|
|
|
|
|
2020-05-23 13:23:24 -07:00
|
|
|
const idealPose = React.useMemo(
|
|
|
|
() => (Math.random() > 0.5 ? "HAPPY_FEM" : "HAPPY_MASC"),
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
2020-05-10 00:21:04 -07:00
|
|
|
const [speciesId, setSpeciesId] = React.useState("1");
|
|
|
|
const [colorId, setColorId] = React.useState("8");
|
|
|
|
const [isValid, setIsValid] = React.useState(true);
|
2020-05-23 13:23:24 -07:00
|
|
|
const [closestPose, setClosestPose] = React.useState(idealPose);
|
2020-05-10 00:21:04 -07:00
|
|
|
|
2020-05-10 00:54:23 -07:00
|
|
|
const onSubmit = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2020-05-10 00:21:04 -07:00
|
|
|
if (!isValid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const params = new URLSearchParams({
|
|
|
|
species: speciesId,
|
|
|
|
color: colorId,
|
2020-05-23 13:23:24 -07:00
|
|
|
pose: closestPose,
|
2020-05-10 00:21:04 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
history.push(`/outfits/new?${params}`);
|
|
|
|
};
|
|
|
|
|
2020-08-12 00:37:31 -07:00
|
|
|
const buttonBgColor = useColorModeValue("green.600", "green.300");
|
|
|
|
const buttonBgColorHover = useColorModeValue("green.700", "green.200");
|
|
|
|
|
2020-05-10 00:21:04 -07:00
|
|
|
return (
|
|
|
|
<form onSubmit={onSubmit}>
|
|
|
|
<Flex>
|
|
|
|
<SpeciesColorPicker
|
|
|
|
speciesId={speciesId}
|
|
|
|
colorId={colorId}
|
2020-05-23 13:23:24 -07:00
|
|
|
idealPose={idealPose}
|
2020-05-10 00:21:04 -07:00
|
|
|
showPlaceholders
|
2020-09-21 02:43:58 -07:00
|
|
|
colorPlaceholderText="Blue"
|
|
|
|
speciesPlaceholderText="Acara"
|
2020-05-23 13:23:24 -07:00
|
|
|
onChange={(species, color, isValid, closestPose) => {
|
2020-05-10 00:21:04 -07:00
|
|
|
setSpeciesId(species.id);
|
|
|
|
setColorId(color.id);
|
|
|
|
setIsValid(isValid);
|
2020-05-23 13:23:24 -07:00
|
|
|
setClosestPose(closestPose);
|
2020-07-22 22:07:45 -07:00
|
|
|
|
|
|
|
if (isValid) {
|
|
|
|
onChange({
|
|
|
|
speciesId: species.id,
|
|
|
|
colorId: color.id,
|
|
|
|
pose: closestPose,
|
|
|
|
});
|
|
|
|
}
|
2020-05-10 00:21:04 -07:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Box width="4" />
|
2020-05-18 01:21:46 -07:00
|
|
|
<Button
|
|
|
|
type="submit"
|
2020-07-20 21:32:42 -07:00
|
|
|
colorScheme="green"
|
2020-05-18 01:21:46 -07:00
|
|
|
disabled={!isValid}
|
2020-08-12 00:37:31 -07:00
|
|
|
backgroundColor={buttonBgColor}
|
|
|
|
_hover={{ backgroundColor: buttonBgColorHover }}
|
2020-05-18 01:21:46 -07:00
|
|
|
>
|
2020-05-10 01:17:16 -07:00
|
|
|
Start
|
|
|
|
</Button>
|
2020-05-10 00:21:04 -07:00
|
|
|
</Flex>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-10 00:54:23 -07:00
|
|
|
function SubmitPetForm() {
|
|
|
|
const history = useHistory();
|
|
|
|
const theme = useTheme();
|
|
|
|
const toast = useToast();
|
|
|
|
|
|
|
|
const [petName, setPetName] = React.useState("");
|
|
|
|
|
|
|
|
const [loadPet, { loading }] = useLazyQuery(
|
|
|
|
gql`
|
2020-05-19 14:48:54 -07:00
|
|
|
query SubmitPetForm($petName: String!) {
|
2020-05-10 00:54:23 -07:00
|
|
|
petOnNeopetsDotCom(petName: $petName) {
|
|
|
|
color {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
species {
|
|
|
|
id
|
|
|
|
}
|
2020-05-23 13:55:59 -07:00
|
|
|
pose
|
2020-05-10 00:54:23 -07:00
|
|
|
items {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
{
|
|
|
|
fetchPolicy: "network-only",
|
|
|
|
onCompleted: (data) => {
|
|
|
|
if (!data) return;
|
|
|
|
|
2020-05-23 13:55:59 -07:00
|
|
|
const { species, color, pose, items } = data.petOnNeopetsDotCom;
|
2020-05-10 00:54:23 -07:00
|
|
|
const params = new URLSearchParams({
|
|
|
|
name: petName,
|
|
|
|
species: species.id,
|
|
|
|
color: color.id,
|
2020-05-23 13:55:59 -07:00
|
|
|
pose,
|
2020-05-10 00:54:23 -07:00
|
|
|
});
|
|
|
|
for (const item of items) {
|
|
|
|
params.append("objects[]", item.id);
|
|
|
|
}
|
|
|
|
history.push(`/outfits/new?${params}`);
|
|
|
|
},
|
|
|
|
onError: () => {
|
|
|
|
toast({
|
|
|
|
title: "We couldn't load that pet, sorry 😓",
|
|
|
|
description: "Is it spelled correctly?",
|
|
|
|
status: "error",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const onSubmit = (e) => {
|
|
|
|
e.preventDefault();
|
2020-05-18 00:20:48 -07:00
|
|
|
|
2020-05-10 00:54:23 -07:00
|
|
|
loadPet({ variables: { petName } });
|
2020-05-18 00:20:48 -07:00
|
|
|
|
|
|
|
// Start preloading the WardrobePage, too!
|
|
|
|
// eslint-disable-next-line no-unused-expressions
|
|
|
|
import("./WardrobePage");
|
2020-05-10 00:54:23 -07:00
|
|
|
};
|
|
|
|
|
2020-08-12 00:37:31 -07:00
|
|
|
const inputBorderColor = useColorModeValue("green.600", "green.500");
|
|
|
|
const inputBorderColorHover = useColorModeValue("green.400", "green.300");
|
|
|
|
const buttonBgColor = useColorModeValue("green.600", "green.300");
|
|
|
|
const buttonBgColorHover = useColorModeValue("green.700", "green.200");
|
|
|
|
|
2020-05-10 00:54:23 -07:00
|
|
|
return (
|
|
|
|
<form onSubmit={onSubmit}>
|
|
|
|
<Flex>
|
|
|
|
<Input
|
|
|
|
value={petName}
|
|
|
|
onChange={(e) => setPetName(e.target.value)}
|
|
|
|
isDisabled={loading}
|
|
|
|
placeholder="Enter a pet's name"
|
2020-05-18 01:21:46 -07:00
|
|
|
aria-label="Enter a pet's name"
|
2020-08-12 00:37:31 -07:00
|
|
|
borderColor={inputBorderColor}
|
|
|
|
_hover={{ borderColor: inputBorderColorHover }}
|
2020-05-10 00:54:23 -07:00
|
|
|
boxShadow="md"
|
|
|
|
width="14em"
|
|
|
|
className={css`
|
|
|
|
&::placeholder {
|
|
|
|
color: ${theme.colors.gray["500"]};
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
/>
|
|
|
|
<Box width="4" />
|
|
|
|
<Button
|
|
|
|
type="submit"
|
2020-07-20 21:32:42 -07:00
|
|
|
colorScheme="green"
|
2020-05-10 00:54:23 -07:00
|
|
|
isDisabled={!petName}
|
|
|
|
isLoading={loading}
|
2020-08-12 00:37:31 -07:00
|
|
|
backgroundColor={buttonBgColor} // for AA contrast
|
|
|
|
_hover={{ backgroundColor: buttonBgColorHover }}
|
2020-05-10 00:54:23 -07:00
|
|
|
>
|
|
|
|
Start
|
|
|
|
</Button>
|
|
|
|
</Flex>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-07 09:48:55 -07:00
|
|
|
function FeedbackFormSection() {
|
|
|
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
|
|
const borderColor = useColorModeValue("gray.300", "blue.400");
|
|
|
|
|
|
|
|
const openButtonRef = React.useRef(null);
|
|
|
|
const emailFieldRef = React.useRef(null);
|
2020-10-07 10:17:52 -07:00
|
|
|
const elementAwaitingFocusRef = React.useRef(null);
|
2020-10-07 09:48:55 -07:00
|
|
|
|
2020-10-07 10:17:52 -07:00
|
|
|
const openForm = React.useCallback(() => {
|
|
|
|
setIsOpen(true);
|
|
|
|
|
|
|
|
// Wait for the re-render to enable the field, then focus it.
|
|
|
|
elementAwaitingFocusRef.current = emailFieldRef.current;
|
|
|
|
}, [setIsOpen]);
|
|
|
|
|
|
|
|
const closeForm = React.useCallback(() => {
|
|
|
|
setIsOpen(false);
|
|
|
|
|
|
|
|
// Wait for the re-render to enable the button, then focus it.
|
|
|
|
elementAwaitingFocusRef.current = openButtonRef.current;
|
|
|
|
}, [setIsOpen]);
|
|
|
|
|
|
|
|
// This lil layout effect will focus whatever element is awaiting focus, then
|
|
|
|
// clear it out. We use this to set up focus() calls, but wait until the next
|
|
|
|
// layout finishes to actually call them.
|
2020-10-07 09:48:55 -07:00
|
|
|
React.useLayoutEffect(() => {
|
2020-10-07 10:17:52 -07:00
|
|
|
if (elementAwaitingFocusRef.current) {
|
|
|
|
elementAwaitingFocusRef.current.focus();
|
|
|
|
elementAwaitingFocusRef.current = null;
|
2020-10-07 09:48:55 -07:00
|
|
|
}
|
2020-10-07 10:17:52 -07:00
|
|
|
});
|
2020-10-07 09:48:55 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Flex
|
|
|
|
as="section"
|
|
|
|
position="relative"
|
|
|
|
alignItems="center"
|
|
|
|
border="1px solid"
|
|
|
|
borderColor={borderColor}
|
|
|
|
borderRadius="lg"
|
|
|
|
boxShadow="lg"
|
|
|
|
maxWidth="500px"
|
|
|
|
paddingLeft="2"
|
|
|
|
paddingRight="4"
|
|
|
|
paddingY="2"
|
|
|
|
cursor={!isOpen && "pointer"}
|
2020-10-07 10:17:52 -07:00
|
|
|
onClick={!isOpen ? openForm : null}
|
2020-10-07 09:48:55 -07:00
|
|
|
>
|
2020-10-09 08:01:46 -07:00
|
|
|
<Box padding="2" borderRadius="lg" overflow="hidden" flex="0 0 auto">
|
2020-10-07 09:48:55 -07:00
|
|
|
<Box
|
|
|
|
as="img"
|
2020-10-09 08:01:46 -07:00
|
|
|
src={FeedbackXweeImg}
|
|
|
|
srcSet={`${FeedbackXweeImg} 1x, ${FeedbackXweeImg2x} 2x`}
|
2020-10-07 09:48:55 -07:00
|
|
|
height="90px"
|
|
|
|
width="90px"
|
|
|
|
opacity="0.9"
|
2020-10-09 08:01:46 -07:00
|
|
|
alt=""
|
2020-10-07 09:48:55 -07:00
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
display="grid"
|
|
|
|
gridTemplateAreas="the-single-area"
|
|
|
|
alignItems="center"
|
|
|
|
marginLeft="2"
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
position="absolute"
|
|
|
|
left="1"
|
|
|
|
top="1"
|
|
|
|
aria-hidden={!isOpen}
|
|
|
|
isDisabled={!isOpen}
|
|
|
|
opacity={isOpen ? "0.5" : "0"}
|
|
|
|
pointerEvents={isOpen ? "all" : "none"}
|
|
|
|
transition="opacity 0.25s"
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
aria-label="Close"
|
|
|
|
icon={<CloseIcon />}
|
|
|
|
size="xs"
|
|
|
|
variant="ghost"
|
2020-10-07 10:17:52 -07:00
|
|
|
onClick={closeForm}
|
2020-10-07 09:48:55 -07:00
|
|
|
isDisabled={!isOpen}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
gridArea="the-single-area"
|
|
|
|
aria-hidden={isOpen}
|
|
|
|
opacity={isOpen ? "0" : "1"}
|
|
|
|
pointerEvents={isOpen ? "none" : "all"}
|
|
|
|
transition="opacity 0.25s"
|
|
|
|
>
|
|
|
|
<FeedbackFormPitch
|
|
|
|
isDisabled={isOpen}
|
2020-10-07 10:17:52 -07:00
|
|
|
onClick={openForm}
|
2020-10-07 09:48:55 -07:00
|
|
|
openButtonRef={openButtonRef}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
gridArea="the-single-area"
|
|
|
|
aria-hidden={!isOpen}
|
|
|
|
opacity={isOpen ? "1" : "0"}
|
|
|
|
pointerEvents={isOpen ? "all" : "none"}
|
|
|
|
transition="opacity 0.25s"
|
|
|
|
>
|
|
|
|
<FeedbackForm
|
|
|
|
isDisabled={!isOpen}
|
2020-10-07 10:17:52 -07:00
|
|
|
onClose={closeForm}
|
2020-10-07 09:48:55 -07:00
|
|
|
emailFieldRef={emailFieldRef}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
</Flex>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedbackFormPitch({ isDisabled, onClick, openButtonRef }) {
|
|
|
|
return (
|
|
|
|
<Flex direction="column" textAlign="left" opacity="0.9">
|
|
|
|
<Box as="header">Hi friends! Welcome to the beta!</Box>
|
|
|
|
<Box as="p" fontSize="sm">
|
|
|
|
This is the new Dress to Impress! It's ready for the future, and it even
|
|
|
|
works great on mobile! More coming soon!
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
as="button"
|
|
|
|
alignSelf="flex-end"
|
|
|
|
fontSize="sm"
|
|
|
|
marginTop="1"
|
|
|
|
opacity="0.8"
|
|
|
|
textDecoration="underline"
|
|
|
|
disabled={isDisabled}
|
|
|
|
onClick={onClick}
|
|
|
|
ref={openButtonRef}
|
|
|
|
>
|
2020-10-10 03:13:12 -07:00
|
|
|
Got ideas? Send us your feedback →
|
2020-10-07 09:48:55 -07:00
|
|
|
</Box>
|
|
|
|
</Flex>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedbackForm({ isDisabled, onClose, emailFieldRef }) {
|
|
|
|
const [content, setContent] = React.useState("");
|
2020-10-09 08:18:18 -07:00
|
|
|
const [email, setEmail] = useLocalStorage("DTIFeedbackFormEmail", "");
|
|
|
|
const [isSending, setIsSending] = React.useState(false);
|
2020-10-07 09:48:55 -07:00
|
|
|
const toast = useToast();
|
|
|
|
|
2020-10-09 08:18:18 -07:00
|
|
|
const onSubmit = React.useCallback(
|
|
|
|
(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
fetch("/api/sendFeedback", {
|
|
|
|
method: "POST",
|
2020-10-09 08:55:03 -07:00
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
body: JSON.stringify({ content, email }),
|
2020-10-09 08:18:18 -07:00
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
if (!res.ok) {
|
|
|
|
throw new Error(`/api/sendFeedback returned status ${res.status}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
setIsSending(false);
|
|
|
|
setContent("");
|
|
|
|
onClose();
|
|
|
|
toast({
|
|
|
|
status: "success",
|
|
|
|
title: "Got it! We'll take a look soon.",
|
|
|
|
description:
|
|
|
|
"Thanks for helping us get better! Best wishes to you and your " +
|
|
|
|
"pets!!",
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
setIsSending(false);
|
|
|
|
console.error(e);
|
|
|
|
toast({
|
|
|
|
status: "warning",
|
|
|
|
title: "Oops, we had an error sending this, sorry!",
|
|
|
|
description:
|
|
|
|
"We'd still love to hear from you! Please reach out to " +
|
|
|
|
"matchu@openneo.net with whatever's on your mind. Thanks and " +
|
|
|
|
"enjoy the site!",
|
|
|
|
duration: null,
|
|
|
|
isClosable: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
setIsSending(true);
|
|
|
|
},
|
2020-10-10 01:25:10 -07:00
|
|
|
[content, email, onClose, toast]
|
2020-10-09 08:18:18 -07:00
|
|
|
);
|
|
|
|
|
2020-10-07 09:48:55 -07:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
as="form"
|
|
|
|
// We use Grid here rather than our usual Flex, mainly so the fields will
|
|
|
|
// tab in the correct order!
|
|
|
|
display="grid"
|
|
|
|
gridTemplateAreas={`"email send" "content content"`}
|
|
|
|
gridTemplateColumns="1fr auto"
|
|
|
|
gridGap="2"
|
2020-10-09 08:18:18 -07:00
|
|
|
onSubmit={onSubmit}
|
2020-10-07 09:48:55 -07:00
|
|
|
onKeyDown={(e) => {
|
|
|
|
if (e.key === "Escape") {
|
|
|
|
onClose();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Input
|
|
|
|
type="email"
|
|
|
|
placeholder="Email address (optional)"
|
|
|
|
size="sm"
|
|
|
|
gridArea="email"
|
2020-10-09 08:18:18 -07:00
|
|
|
value={email}
|
|
|
|
onChange={(e) => setEmail(e.target.value)}
|
2020-10-07 09:48:55 -07:00
|
|
|
ref={emailFieldRef}
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
/>
|
|
|
|
<Textarea
|
|
|
|
size="sm"
|
|
|
|
placeholder={"I love…\nI wish…\nNext, you should add…"}
|
|
|
|
gridArea="content"
|
|
|
|
value={content}
|
|
|
|
onChange={(e) => setContent(e.target.value)}
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
size="sm"
|
|
|
|
colorScheme="blue"
|
|
|
|
gridArea="send"
|
|
|
|
isDisabled={isDisabled || content.trim().length === 0}
|
2020-10-09 08:18:18 -07:00
|
|
|
isLoading={isSending}
|
2020-10-07 09:48:55 -07:00
|
|
|
>
|
|
|
|
Send
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-31 16:57:37 -07:00
|
|
|
/**
|
|
|
|
* useSupportSetup helps our support staff get set up with special access.
|
|
|
|
* If you provide ?supportSecret=... in the URL, we'll save it in a cookie and
|
|
|
|
* pop up a toast!
|
|
|
|
*
|
|
|
|
* This doesn't guarantee the secret is correct, of course! We don't bother to
|
|
|
|
* check that here; the server will reject requests from bad support secrets.
|
|
|
|
* And there's nothing especially secret in the support UI, so it's okay if
|
|
|
|
* other people know about the tools and poke around a powerless interface!
|
|
|
|
*/
|
|
|
|
function useSupportSetup() {
|
|
|
|
const location = useLocation();
|
|
|
|
const toast = useToast();
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
const params = new URLSearchParams(location.search);
|
|
|
|
const supportSecret = params.get("supportSecret");
|
2020-08-01 00:42:36 -07:00
|
|
|
const existingSupportSecret = localStorage.getItem("supportSecret");
|
2020-07-31 16:57:37 -07:00
|
|
|
|
2020-08-01 00:42:36 -07:00
|
|
|
if (supportSecret && supportSecret !== existingSupportSecret) {
|
2020-07-31 16:57:37 -07:00
|
|
|
localStorage.setItem("supportSecret", supportSecret);
|
|
|
|
|
|
|
|
toast({
|
|
|
|
title: "Support secret saved!",
|
|
|
|
description:
|
|
|
|
`You should now see special Support UI across the site. ` +
|
|
|
|
`Thanks for your help! 💖`,
|
|
|
|
status: "success",
|
|
|
|
duration: 10000,
|
|
|
|
isClosable: true,
|
|
|
|
});
|
|
|
|
} else if (supportSecret === "") {
|
|
|
|
localStorage.removeItem("supportSecret");
|
|
|
|
|
|
|
|
toast({
|
|
|
|
title: "Support secret deleted.",
|
|
|
|
description: `The Support UI will now stop appearing on this device.`,
|
|
|
|
status: "success",
|
|
|
|
duration: 10000,
|
|
|
|
isClosable: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [location, toast]);
|
|
|
|
}
|
|
|
|
|
2020-05-10 00:21:04 -07:00
|
|
|
export default HomePage;
|