diff --git a/apps/cms/src/admin/views/MerchOverview.tsx b/apps/cms/src/admin/views/MerchOverview.tsx index 1a5b3598..f29b952e 100644 --- a/apps/cms/src/admin/views/MerchOverview.tsx +++ b/apps/cms/src/admin/views/MerchOverview.tsx @@ -1,9 +1,49 @@ -import React from "react"; +import React, { useEffect, useState, ChangeEvent } from "react"; import { Button } from "payload/components/elements"; import { AdminView } from "payload/config"; import ViewTemplate from "./ViewTemplate"; +import StoreApi from "../../apis/store.api"; const MerchOverview: AdminView = ({ user, canAccessAdmin }) => { + const [displayText, setDisplayText] = useState( + "We are currently preparing for the next merch sale. Please look forward to our email!" + ); + const [isStoreDisabled, setIsStoreDisabled] = useState(true); + const [loading, setLoading] = useState(true); + + const SHOW_DISPLAY_TEXT_INPUT = false; + + useEffect(() => { + const fetchStoreStatus = async () => { + try { + const { disabled } = await StoreApi.getStoreStatus(); + setIsStoreDisabled(disabled); + setLoading(false); + } catch (error) { + console.error(error); + setLoading(false); + } + }; + + // eslint-disable-next-line @typescript-eslint/no-floating-promises + fetchStoreStatus(); + }, []); + + const disableStore = async () => { + // TODO: Calls api to disable merch store + try { + setLoading(true); + await StoreApi.setStoreStatus({ + displayText, + disabled: !isStoreDisabled, + }); + setIsStoreDisabled(!isStoreDisabled); + setLoading(false); + } catch (error) { + console.error(error); + setLoading(false); + } + }; return ( { +

{`Current state of merch store: ${ + loading ? "..." : isStoreDisabled ? "Disabled" : "Live" + }`}

+ {SHOW_DISPLAY_TEXT_INPUT && ( +