Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
limivann committed Jan 31, 2024
1 parent f36a151 commit 3d0aa1a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 33 deletions.
55 changes: 37 additions & 18 deletions apps/cms/src/admin/views/MerchOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, ChangeEvent } from "react";
import { Button } from "payload/components/elements";
import { AdminView } from "payload/config";
import ViewTemplate from "./ViewTemplate";
Expand All @@ -11,24 +11,38 @@ const MerchOverview: AdminView = ({ user, canAccessAdmin }) => {
const [isStoreDisabled, setIsStoreDisabled] = useState<boolean>(true);
const [loading, setLoading] = useState<boolean>(true);

const SHOW_DISPLAY_TEXT_INPUT = false;

useEffect(() => {
const fetchStoreStatus = async () => {
const { disabled } = await StoreApi.getStoreStatus();
setIsStoreDisabled(disabled);
setLoading(false);
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
setLoading(true);
await StoreApi.setStoreStatus({
displayText,
disabled: !isStoreDisabled,
});
setIsStoreDisabled(!isStoreDisabled);
setLoading(false);
try {
setLoading(true);
await StoreApi.setStoreStatus({
displayText,
disabled: !isStoreDisabled,
});
setIsStoreDisabled(!isStoreDisabled);
setLoading(false);
} catch (error) {
console.error(error);
setLoading(false);
}
};
return (
<ViewTemplate
Expand All @@ -48,14 +62,19 @@ const MerchOverview: AdminView = ({ user, canAccessAdmin }) => {
<p style={{ paddingTop: 20 }}>{`Current state of merch store: ${
loading ? "..." : isStoreDisabled ? "Disabled" : "Live"
}`}</p>
{/* <textarea
value={displayText}
onChange={(e) => setDisplayText(e.target.value)}
placeholder="Enter display text"
rows={4}
cols={50}
/> */}
{SHOW_DISPLAY_TEXT_INPUT && (
<textarea
value={displayText}
onChange={(e: ChangeEvent<HTMLTextAreaElement>) =>
setDisplayText(e.target.value)
}
placeholder="Enter display text"
rows={4}
cols={50}
/>
)}
<Button
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onClick={disableStore}
disabled={loading}
buttonStyle="primary"
Expand Down
29 changes: 19 additions & 10 deletions apps/cms/src/apis/store.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,32 @@ class MerchStoreApi {
displayText,
}: MerchSaleStatus): Promise<void> {
// TODO: set store status in the backend
console.log(disabled, displayText);
return new Promise((res, rej) => {
setTimeout(() => {
res();
}, 1000);
try {
setTimeout(() => {
res();
}, 1000);
} catch (error) {
rej(error);
}
});
}

async getStoreStatus(): Promise<MerchSaleStatus> {
// TODO: get store status from the backend
return new Promise((res, rej) => {
setTimeout(() => {
res({
disabled: true,
displayText:
"We are currently preparing for the next merch sale. Please look forward to our email!",
});
}, 1000);
try {
setTimeout(() => {
res({
disabled: true,
displayText:
"We are currently preparing for the next merch sale. Please look forward to our email!",
});
}, 1000);
} catch (error) {
rej(error);
}
});
}
}
Expand Down
19 changes: 14 additions & 5 deletions apps/web/pages/merch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ const MerchandiseList = () => {
const [selectedCategory, setSelectedCategory] = useState<string>("");
const [isMerchDisabled, setIsMerchDisabled] = useState<boolean | null>(false);
const [disabledText, setDisabledText] = useState<string>("");
const [loading, setLoading] = useState<boolean>(true);

useEffect(() => {
const fetchMerchSaleStatus = async () => {
const { disabled, displayText } = await api.getMerchSaleStatus();
console.log(disabledText);
setDisabledText(displayText ?? "");
setIsMerchDisabled(disabled);
try {
// TODO: change to use query?
const { disabled, displayText } = await api.getMerchSaleStatus();
setDisabledText(displayText ?? "");
setIsMerchDisabled(disabled);
setLoading(false);
} catch (error) {
// TODO: display error
setLoading(false);
}
};

// eslint-disable-next-line @typescript-eslint/no-floating-promises
fetchMerchSaleStatus();
}, []);

Expand All @@ -39,7 +48,7 @@ const MerchandiseList = () => {
setSelectedCategory(event.target.value);
};

if (isMerchDisabled === null) {
if (loading) {
return (
<>
<MerchListSkeleton />
Expand Down

0 comments on commit 3d0aa1a

Please sign in to comment.