From 95af78ef088e481c4ac280f3c8a99c53b6318a85 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 26 Oct 2023 16:36:45 -0300 Subject: [PATCH] refactor(market-card.tsx): remove unused handleFork function to improve code readability and maintainability feat(market-card.tsx): add setErrorData function to alertContext to handle error messages when adding a component feat(market-card.tsx): add setSuccessData function to alertContext to display success message when adding a component --- .../StorePage/components/market-card.tsx | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/frontend/src/pages/StorePage/components/market-card.tsx b/src/frontend/src/pages/StorePage/components/market-card.tsx index 5a8927af2..8816c63df 100644 --- a/src/frontend/src/pages/StorePage/components/market-card.tsx +++ b/src/frontend/src/pages/StorePage/components/market-card.tsx @@ -23,7 +23,7 @@ export const MarketCardComponent = ({ data }: { data: storeComponent }) => { const [added, setAdded] = useState(savedFlows.has(data.id) ? true : false); const [loading, setLoading] = useState(false); const { addFlow } = useContext(TabsContext); - const { setSuccessData } = useContext(alertContext); + const { setSuccessData, setErrorData } = useContext(alertContext); const flowData = useRef(); useEffect(() => { @@ -42,9 +42,14 @@ export const MarketCardComponent = ({ data }: { data: storeComponent }) => { .then(() => { setAdded(true); setLoading(false); + setSuccessData({ title: "Component Added to account" }); }) .catch((error) => { console.error(error); + setErrorData({ + title: "Error on adding Component", + list: [error["response"]["data"]["detail"]], + }); }); }, (error) => { @@ -69,28 +74,6 @@ export const MarketCardComponent = ({ data }: { data: storeComponent }) => { } } - function handleFork(flowId: string, is_component: boolean) { - getComponent(flowId).then( - (res) => { - console.log(res); - const newFLow = cloneFLowWithParent(res.data, res.id, is_component); - console.log(newFLow); - saveFlowStore(newFLow).then( - (res) => { - console.log(JSON.parse(JSON.stringify(res))); - addFlow(true, newFLow); - }, - (error) => { - console.error(error); - } - ); - }, - (error) => { - console.log(error); - } - ); - } - return (