diff --git a/src/app/api/portfolio/plan/route.ts b/src/app/api/portfolio/plan/route.ts
new file mode 100644
index 0000000..56becb1
--- /dev/null
+++ b/src/app/api/portfolio/plan/route.ts
@@ -0,0 +1,58 @@
+import {
+ portfolio,
+ portfolioUsers,
+ PortfolioGoal,
+ PortfolioStatus,
+ PortfolioRole,
+} from "@/app/db/schema/portfolio";
+import { NextRequest, NextResponse } from "next/server";
+import { db } from "@/app/db/db";
+import { z } from "zod";
+
+const createPortfolioSchema = z.object({
+ userId: z.number(),
+ portfolioName: z.string(),
+ budget: z.number().optional(),
+ goal: z.enum(PortfolioGoal),
+ status: z.enum(PortfolioStatus),
+ role: z.enum(PortfolioRole),
+});
+
+export async function POST(request: NextRequest) {
+ const body = await request.json();
+ console.log("Triggering plan");
+ return new NextResponse(JSON.stringify({ msg: "plan triggered" }), {
+ status: 201,
+ });
+
+ // try {
+ // const validatedBody = createPortfolioSchema.parse(body);
+ // const { userId, portfolioName, budget, goal, status, role } = validatedBody;
+
+ // const creationDate = new Date();
+
+ // const newPortfolio = await db
+ // .insert(portfolio)
+ // .values({
+ // name: portfolioName,
+ // budget: budget,
+ // goal: goal,
+ // status: status,
+ // createdAt: creationDate,
+ // updatedAt: creationDate,
+ // })
+ // .returning({ portfolioId: portfolio.id });
+
+ // const newPortfolioId = newPortfolio[0].portfolioId;
+
+ // const response = await db
+ // .insert(portfolioUsers)
+ // .values({ userId: userId, portfolioId: newPortfolioId, role: role })
+ // .returning();
+
+ // return new NextResponse(JSON.stringify(response), { status: 201 });
+ // } catch (error) {
+ // console.error(error);
+ // throw error;
+ // }
+}
diff --git a/src/app/components/portfolio/UploadCsvModal.tsx b/src/app/components/portfolio/UploadCsvModal.tsx
index 0bfec48..4990ecf 100644
--- a/src/app/components/portfolio/UploadCsvModal.tsx
+++ b/src/app/components/portfolio/UploadCsvModal.tsx
@@ -1,19 +1,82 @@
+"use client";
+
import { Menu, Dialog, Transition } from "@headlessui/react";
import { Fragment, useState } from "react";
import { ChevronDownIcon } from "@heroicons/react/20/solid";
import { Float } from "@headlessui-float/react";
-import ModalSubmit from "@/app/components/home/ModalSubmit";
-
import { Input } from "@/app/shadcn_components/ui/input";
import { Label } from "@/app/shadcn_components/ui/label";
-import { set } from "cypress/types/lodash";
+import { useRouter } from "next/navigation";
+import { useMutation } from "@tanstack/react-query";
+
+export const SubmitPlan = ({
+ buttonDisabled,
+ goal,
+ fundingScheme,
+ goalValue,
+}: {
+ buttonDisabled: boolean;
+ goal: string;
+ fundingScheme: string;
+ goalValue: string;
+}) => {
+ const router = useRouter();
+
+ async function triggerPlanBuild() {
+ const requestBody = JSON.stringify({
+ goal: goal,
+ goalValue: goalValue,
+ fundingScheme: fundingScheme,
+ });
+
+ const response = await fetch("/api/portfolio/plan", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: requestBody,
+ });
+
+ if (!response.ok) {
+ throw new Error("Network response was not ok");
+ }
+
+ return response.json();
+ }
+
+ const { mutate, isLoading } = useMutation(triggerPlanBuild, {
+ onSuccess: (data) => {
+ console.log("uploading csv");
+ // router.push(`/portfolio/${data.id}`);
+ },
+ onError: (error) => {
+ // handle error
+ console.log(error);
+ },
+ });
+
+ const handleSubmit = () => {
+ mutate();
+ };
+
+ return (
+
+ );
+};
export function InputFile() {
return (
-
+
);
}
@@ -21,6 +84,7 @@ export function InputFile() {
type Option = {
label: string;
value: string;
+ disabled: boolean;
};
type DropdownProps = {
@@ -55,7 +119,7 @@ export function SelectDropdown({
>
{options.map((option) => (
-
+
{({ active }) => (