diff --git a/packages/nextjs/app/dashboard/page.tsx b/packages/nextjs/app/dashboard/page.tsx
index a6b5630..7e212d6 100644
--- a/packages/nextjs/app/dashboard/page.tsx
+++ b/packages/nextjs/app/dashboard/page.tsx
@@ -5,12 +5,13 @@ import type { NextPage } from "next";
import ProductCard, { cardData } from "~~/components/ProductCard";
import ProductModal from "~~/components/ProductModal";
import ShopifyModal from "~~/components/ShopifyModal";
+import { Journey } from "~~/types/commontypes";
const Dashboard: NextPage = () => {
const [open, setOpen] = useState(false);
const [shopify, setShopify] = useState(false);
+ const [products, setProducts] = useState([]);
const getAllProducts = async () => {
- console.log("Fetching all products");
try {
const response = await fetch(`/api/journey`, {
method: "GET",
@@ -22,8 +23,7 @@ const Dashboard: NextPage = () => {
throw new Error("Network response was not ok");
}
const data = await response.json();
- console.log(data);
- return response.json();
+ return data;
} catch (error: any) {
console.error(error);
throw new Error(error.message);
@@ -31,8 +31,10 @@ const Dashboard: NextPage = () => {
};
useEffect(() => {
- getAllProducts();
- });
+ getAllProducts().then(data => {
+ setProducts(data);
+ });
+ }, []);
return (
@@ -55,13 +57,13 @@ const Dashboard: NextPage = () => {
- {cardData.map((journey: any) => (
+ {products.map((journey: Journey) => (
))}
diff --git a/packages/nextjs/components/ButtonsList.tsx b/packages/nextjs/components/ButtonsList.tsx
index 337707b..db26767 100644
--- a/packages/nextjs/components/ButtonsList.tsx
+++ b/packages/nextjs/components/ButtonsList.tsx
@@ -4,30 +4,77 @@ import { FrameButtonMetadata, FrameMetadataType } from "@coinbase/onchainkit";
import { IconButton } from "@mui/material";
import { PlusIcon } from "@heroicons/react/24/outline";
import { useProductJourney } from "~~/providers/ProductProvider";
+import { saveFrame } from "~~/services/frames";
import { notification } from "~~/utils/scaffold-eth";
const ButtonList = () => {
- const { frame: dbFrame } = useProductJourney();
- const frame = dbFrame?.frameJson as FrameMetadataType;
- console.log(frame);
+ const { currentFrame, setCurrentFrame, frame } = useProductJourney();
- const [buttons, setButtons] = useState
([{ label: "Button 1" }]);
- const [activeButtonIndex, setActiveButtonIndex] = useState(0);
+ const [activeButtonIndex, setActiveButtonIndex] = useState(0);
useEffect(() => {
- if (!frame) return;
- setButtons(frame.buttons || [{ label: "Button 1" }]);
- }, [frame]);
+ console.log("currentFrame", currentFrame);
+ console.log(activeButtonIndex);
+ console.log(currentFrame?.buttons[activeButtonIndex]);
+ }, [currentFrame, activeButtonIndex]);
+ if (!currentFrame) return null;
const handleAddButton = () => {
- setButtons([...buttons, { label: `Button ${buttons.length + 1}` }]);
+ // @ts-ignore
+ setCurrentFrame(prevFrame => ({
+ ...prevFrame,
+ buttons: [
+ ...(prevFrame?.buttons || []),
+ {
+ label: "New Button",
+ postUrl: "",
+ target: "",
+ },
+ ],
+ }));
};
const handleButtonClick = (index: number) => {
setActiveButtonIndex(index);
};
- const handleSaveFrame = () => {
+ const handleSaveFrame = async () => {
notification.info("Frame saved successfully");
+ const updatedFrame = await saveFrame({
+ _id: frame?._id as string,
+ name: frame?.name as string,
+ frameJson: currentFrame as FrameMetadataType,
+ });
+ console.log(updatedFrame);
+ };
+
+ const handleSave = (button: FrameButtonMetadata) => {
+ if (currentFrame) {
+ // @ts-ignore
+ const newButtons = [...currentFrame.buttons];
+ newButtons[activeButtonIndex] = button;
+ setCurrentFrame({
+ ...currentFrame,
+ // @ts-ignore
+ buttons: newButtons,
+ });
+ }
+ };
+
+ const handleDelete = () => {
+ if (!currentFrame) return;
+ if (currentFrame?.buttons?.length === 1) {
+ notification.error("At least one button is required");
+ return;
+ }
+ const newButtons = [...currentFrame.buttons];
+ newButtons.splice(activeButtonIndex, 1);
+ // @ts-ignore
+ setCurrentFrame({
+ ...currentFrame,
+ // @ts-ignore
+ buttons: newButtons,
+ });
+ setActiveButtonIndex(0);
};
return (
@@ -35,38 +82,23 @@ const ButtonList = () => {
- {buttons.length < 4 && (
+ {/* @ts-ignore*/}
+ {currentFrame?.buttons?.length < 4 && (
)}
- {buttons.map((button, index) => (
+ {currentFrame?.buttons?.map((button, index) => (
))}
- {activeButtonIndex !== null && (
- {
- const newButtons = [...buttons];
- newButtons[activeButtonIndex] = button;
- setButtons(newButtons);
- }}
- onDelete={() => {
- const newButtons = [...buttons];
- if (newButtons.length === 1) {
- notification.error("At least one button is required");
- return;
- }
- newButtons.splice(activeButtonIndex, 1);
- setButtons(newButtons);
- setActiveButtonIndex(null);
- }}
- />
+ {/* @ts-ignore */}
+ {currentFrame?.buttons[activeButtonIndex] && (
+
)}