mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
Fixing bug with hardcoded userId and creation of portfolio|
This commit is contained in:
parent
261a8179f5
commit
6748d0a625
3 changed files with 21 additions and 3 deletions
|
|
@ -46,7 +46,10 @@ export async function POST(request: NextRequest) {
|
|||
.values({ userId: userId, portfolioId: newPortfolioId, role: role })
|
||||
.returning();
|
||||
|
||||
return new NextResponse(JSON.stringify(response), { status: 201 });
|
||||
if (response.length !== 1) {
|
||||
throw new Error("Got back more than one row from insert - investigate");
|
||||
}
|
||||
return new NextResponse(JSON.stringify(response[0]), { status: 201 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React from "react";
|
|||
import StatusBadge from "@/app/components/StatusBadge";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { PortfolioStatus } from "@/app/db/schema/portfolio";
|
||||
import { formatNumber } from "@/app/utils";
|
||||
|
||||
const styles = {
|
||||
wrapper:
|
||||
|
|
@ -28,6 +29,8 @@ const Card = ({ id, title, image, budget, status }: CardProps) => {
|
|||
router.push(`/portfolio/${id}`);
|
||||
}
|
||||
|
||||
const budgetFormatted = budget ? "£" + formatNumber(budget) : "";
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
|
|
@ -41,7 +44,7 @@ const Card = ({ id, title, image, budget, status }: CardProps) => {
|
|||
</div>
|
||||
<div className={styles.textWrapper}>
|
||||
<h1>{`${title}`}</h1>
|
||||
<div>{budget}</div>
|
||||
<div>{budgetFormatted}</div>
|
||||
</div>
|
||||
<div className="mb-2 flex justify-end w-full">
|
||||
<StatusBadge status={status} />
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {
|
||||
|
|
@ -5,6 +7,7 @@ import {
|
|||
PortfolioGoal,
|
||||
PortfolioRole,
|
||||
} from "@/app/db/schema/portfolio";
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
type CreatePortfolioArgs = {
|
||||
userId: number;
|
||||
|
|
@ -60,6 +63,15 @@ const ModalSubmit = ({
|
|||
}) => {
|
||||
const router = useRouter();
|
||||
|
||||
// This is a client component so we can access the session directly
|
||||
const session = useSession();
|
||||
|
||||
if (!session.data) {
|
||||
// The user is not logged in, redirect them to sign in
|
||||
router.push("/");
|
||||
return null;
|
||||
}
|
||||
|
||||
const { mutate, isLoading } = useMutation(createPortfolio, {
|
||||
onSuccess: (data) => {
|
||||
router.push(`/portfolio/${data.id}`);
|
||||
|
|
@ -71,7 +83,7 @@ const ModalSubmit = ({
|
|||
});
|
||||
|
||||
const handleSubmit = () => {
|
||||
const userId = 2;
|
||||
const userId = session.data.user.dbId;
|
||||
const status = "scoping";
|
||||
const role = "creator";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue