fix(StorePage/index.tsx): fix typo in import statement for getStoreComponents function

feat(StorePage/index.tsx): add support for saving flow store and searching for a component in API controller
feat(StorePage/index.tsx): add support for cloning a flow with parent and saving it to flow store
feat(StorePage/index.tsx): add support for adding a cloned flow to tabs context
feat(StorePage/index.tsx): add test button to test cloning and saving flow
feat(types/flow/index.ts): add parent property to FlowType to track parent flow
feat(utils/storeUtils.ts): add utility function to clone a flow with parent
This commit is contained in:
anovazzi1 2023-10-23 21:54:09 -03:00
commit 9f7fe0545c
3 changed files with 49 additions and 1 deletions

View file

@ -17,9 +17,15 @@ import { Switch } from "../../components/ui/switch";
import { alertContext } from "../../contexts/alertContext"; import { alertContext } from "../../contexts/alertContext";
import { AuthContext } from "../../contexts/authContext"; import { AuthContext } from "../../contexts/authContext";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
import { getStoreComponents, searchComponent } from "../../controllers/API"; import {
getComponent,
getStoreComponents,
saveFlowStore,
searchComponent,
} from "../../controllers/API";
import StoreApiKeyModal from "../../modals/StoreApiKeyModal"; import StoreApiKeyModal from "../../modals/StoreApiKeyModal";
import { FlowComponent } from "../../types/store"; import { FlowComponent } from "../../types/store";
import cloneFLowWithParent from "../../utils/storeUtils";
import { cn } from "../../utils/utils"; import { cn } from "../../utils/utils";
import { MarketCardComponent } from "./components/market-card"; import { MarketCardComponent } from "./components/market-card";
export default function StorePage(): JSX.Element { export default function StorePage(): JSX.Element {
@ -39,6 +45,7 @@ export default function StorePage(): JSX.Element {
const [searchData, setSearchData] = useState(data); const [searchData, setSearchData] = useState(data);
const [errorApiKey, setErrorApiKey] = useState(false); const [errorApiKey, setErrorApiKey] = useState(false);
const { setErrorData } = useContext(alertContext); const { setErrorData } = useContext(alertContext);
const { addFlow } = useContext(TabsContext);
useEffect(() => { useEffect(() => {
handleGetComponents(); handleGetComponents();
@ -51,6 +58,7 @@ export default function StorePage(): JSX.Element {
console.log(res); console.log(res);
setLoading(false); setLoading(false);
setErrorApiKey(false); setErrorApiKey(false);
setData(res);
}) })
.catch((err) => { .catch((err) => {
setLoading(false); setLoading(false);
@ -76,6 +84,27 @@ export default function StorePage(): JSX.Element {
const errorMessage = errorApiKey && !loading; const errorMessage = errorApiKey && !loading;
const renderComponents = !loading && !errorApiKey && apiKey; const renderComponents = !loading && !errorApiKey && apiKey;
function handleFork(flowId: string) {
getComponent(flowId).then(
(res) => {
console.log(res);
const newFLow = cloneFLowWithParent(res);
saveFlowStore(newFLow).then(
(res) => {
console.log(res);
addFlow(true, newFLow);
},
(error) => {
console.error(error);
}
);
},
(error) => {
console.log(error);
}
);
}
return ( return (
<> <>
<Header /> <Header />
@ -196,6 +225,14 @@ export default function StorePage(): JSX.Element {
.map((item, idx) => ( .map((item, idx) => (
<MarketCardComponent key={idx} data={item} onAdd={() => {}} /> <MarketCardComponent key={idx} data={item} onAdd={() => {}} />
))} ))}
<button
onClick={() => {
console.log(data);
handleFork(data[0].id);
}}
>
test
</button>
</div> </div>
</div> </div>
)} )}

View file

@ -8,6 +8,7 @@ export type FlowType = {
description: string; description: string;
style?: FlowStyleType; style?: FlowStyleType;
is_component?: boolean; is_component?: boolean;
parent?: string;
}; };
export type NodeType = { export type NodeType = {
id: string; id: string;

View file

@ -0,0 +1,10 @@
import { cloneDeep } from "lodash";
import { FlowType } from "../types/flow";
export default function cloneFLowWithParent(flow: FlowType) {
const parent = flow.id;
let childFLow = cloneDeep(flow);
childFLow.parent = parent;
childFLow.id = "";
return childFLow;
}