import * as React from "react"; import gql from "graphql-tag"; import { useQuery, useMutation } from "@apollo/client"; import { Badge, Box, Drawer, DrawerBody, DrawerCloseButton, DrawerContent, DrawerHeader, DrawerOverlay, FormControl, FormErrorMessage, FormHelperText, FormLabel, Link, Select, Spinner, useBreakpointValue, } from "@chakra-ui/core"; import { CheckCircleIcon, ExternalLinkIcon } from "@chakra-ui/icons"; import useSupportSecret from "./useSupportSecret"; /** * ItemSupportDrawer shows Support UI for the item when open. * * This component controls the drawer element. The actual content is imported * from another lazy-loaded component! */ function ItemSupportDrawer({ item, isOpen, onClose }) { const placement = useBreakpointValue({ base: "bottom", lg: "right", // TODO: There's a bug in the Chakra RC that doesn't read the breakpoint // specification correctly - we need these extra keys until it's fixed! // https://github.com/chakra-ui/chakra-ui/issues/1444 0: "bottom", 1: "bottom", 2: "right", 3: "right", }); return ( {item.name} Support ); } function SpecialColorFields({ item }) { const supportSecret = useSupportSecret(); const { loading, error, data } = useQuery( gql` query ItemSupportDrawerSpecialColorFields($itemId: ID!) { allColors { id name isStandard } item(id: $itemId) { manualSpecialColor { id } } } `, { variables: { itemId: item.id } } ); const [ mutate, { loading: loading2, error: error2, data: data2 }, ] = useMutation(gql` mutation ItemSupportDrawerSetManualSpecialColor( $itemId: ID! $colorId: ID $supportSecret: String! ) { setManualSpecialColor( itemId: $itemId colorId: $colorId supportSecret: $supportSecret ) { manualSpecialColor { __typename id } } } `); const nonStandardColors = data?.allColors?.filter((c) => !c.isStandard) || []; nonStandardColors.sort((a, b) => a.name.localeCompare(b.name)); return ( Special color {error && {error.message}} {error2 && {error2.message}} {!error && ( This controls which previews we show on the{" "} item page . )} ); } export default ItemSupportDrawer;