migrate to new useSupport hook

Just smoothing out the API for cases where you want to know `isSupportUser`, but not the secret!
This commit is contained in:
Emi Matchu 2020-08-29 14:54:02 -07:00
parent 4e923746ce
commit 5ce5356825
5 changed files with 11 additions and 37 deletions

View file

@ -31,7 +31,7 @@ import SpeciesColorPicker from "../../components/SpeciesColorPicker";
import useOutfitAppearance, {
itemAppearanceFragment,
} from "../../components/useOutfitAppearance";
import useSupportSecret from "./useSupportSecret";
import useSupport from "./useSupport";
/**
* ItemLayerSupportModal offers Support info and tools for a specific item
@ -52,7 +52,7 @@ function ItemLayerSupportModal({
isValid: true,
});
const [uploadModalIsOpen, setUploadModalIsOpen] = React.useState(false);
const supportSecret = useSupportSecret();
const { supportSecret } = useSupport();
const toast = useToast();
const [
@ -362,7 +362,7 @@ function ItemLayerSupportModalRemoveButton({
}) {
const { isOpen, onOpen, onClose } = useDisclosure();
const toast = useToast();
const supportSecret = useSupportSecret();
const { supportSecret } = useSupport();
const [mutate, { loading, error }] = useMutation(
gql`

View file

@ -15,7 +15,7 @@ import {
} from "@chakra-ui/core";
import { ExternalLinkIcon } from "@chakra-ui/icons";
import useSupportSecret from "./useSupportSecret";
import useSupport from "./useSupport";
/**
* ItemLayerSupportUploadModal helps Support users create and upload PNGs for
@ -36,7 +36,7 @@ function ItemLayerSupportUploadModal({ item, itemLayer, isOpen, onClose }) {
const [conflictMode, setConflictMode] = React.useState("onBlack");
const supportSecret = useSupportSecret();
const { supportSecret } = useSupport();
const toast = useToast();
const apolloClient = useApolloClient();

View file

@ -32,7 +32,7 @@ import Metadata, { MetadataLabel, MetadataValue } from "./Metadata";
import { OutfitLayers } from "../../components/OutfitPreview";
import useOutfitAppearance from "../../components/useOutfitAppearance";
import { OutfitStateContext } from "../useOutfitState";
import useSupportSecret from "./useSupportSecret";
import useSupport from "./useSupport";
/**
* ItemSupportDrawer shows Support UI for the item when open.
@ -195,7 +195,7 @@ function ItemSupportSpecialColorFields({
item,
manualSpecialColor,
}) {
const supportSecret = useSupportSecret();
const { supportSecret } = useSupport();
const {
loading: colorsLoading,
@ -324,7 +324,7 @@ function ItemSupportPetCompatibilityRuleFields({
item,
explicitlyBodySpecific,
}) {
const supportSecret = useSupportSecret();
const { supportSecret } = useSupport();
const [
mutate,

View file

@ -1,4 +1,4 @@
import useSupportSecret from "./useSupportSecret";
import useSupport from "./useSupport";
/**
* SupportOnly only shows its contents to Support users. For most users, the
@ -12,8 +12,8 @@ import useSupportSecret from "./useSupportSecret";
* the server checks the provided secret for each Support request.
*/
function SupportOnly({ children }) {
const supportSecret = useSupportSecret();
return supportSecret ? children : null;
const { isSupportUser } = useSupport();
return isSupportUser ? children : null;
}
export default SupportOnly;

View file

@ -1,26 +0,0 @@
import * as React from "react";
/**
* useSupportSecret returns the Support secret that the server requires for
* Support actions... if the user has it set. For most users, this returns
* nothing!
*
* To become a Support user, you visit /?supportSecret=..., which saves the
* secret to your device.
*
* Note that this hook doesn't check that the secret is *correct*, so it's
* possible that it will return an invalid secret. That's okay, because
* the server checks the provided secret for each Support request.
*
* DEPRECATED: Use `useSupport` instead!
*/
function useSupportSecret() {
return React.useMemo(() => localStorage.getItem("supportSecret"), []);
}
export function useIsSupportUser() {
const supportSecret = useSupportSecret();
return supportSecret != null;
}
export default useSupportSecret;