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 }) => ( - {"Submit button goes here"} - {/* */} + goal={goalValue} + fundingScheme={fundingScheme} + goalValue={goalValue} + /> diff --git a/src/app/shadcn_components/ui/select.tsx b/src/app/shadcn_components/ui/select.tsx new file mode 100644 index 0000000..16429d6 --- /dev/null +++ b/src/app/shadcn_components/ui/select.tsx @@ -0,0 +1,121 @@ +"use client" + +import * as React from "react" +import * as SelectPrimitive from "@radix-ui/react-select" +import { Check, ChevronDown } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Select = SelectPrimitive.Root + +const SelectGroup = SelectPrimitive.Group + +const SelectValue = SelectPrimitive.Value + +const SelectTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + {children} + + + + +)) +SelectTrigger.displayName = SelectPrimitive.Trigger.displayName + +const SelectContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, position = "popper", ...props }, ref) => ( + + + + {children} + + + +)) +SelectContent.displayName = SelectPrimitive.Content.displayName + +const SelectLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SelectLabel.displayName = SelectPrimitive.Label.displayName + +const SelectItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + + + + + {children} + +)) +SelectItem.displayName = SelectPrimitive.Item.displayName + +const SelectSeparator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +SelectSeparator.displayName = SelectPrimitive.Separator.displayName + +export { + Select, + SelectGroup, + SelectValue, + SelectTrigger, + SelectContent, + SelectLabel, + SelectItem, + SelectSeparator, +}