Make it work

This commit is contained in:
Sebastien Castiel
2023-12-15 12:28:34 -05:00
parent 564f192013
commit 95bbcf352f
7 changed files with 67 additions and 58 deletions

89
package-lock.json generated
View File

@@ -25,7 +25,7 @@
"clsx": "^2.0.0", "clsx": "^2.0.0",
"lucide-react": "^0.290.0", "lucide-react": "^0.290.0",
"nanoid": "^5.0.4", "nanoid": "^5.0.4",
"next": "^14.0.5-canary.12", "next": "^14.0.1",
"next-plausible": "^3.12.0", "next-plausible": "^3.12.0",
"next-themes": "^0.2.1", "next-themes": "^0.2.1",
"next13-progressbar": "^1.1.1", "next13-progressbar": "^1.1.1",
@@ -280,9 +280,9 @@
} }
}, },
"node_modules/@next/env": { "node_modules/@next/env": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/env/-/env-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/env/-/env-14.0.1.tgz",
"integrity": "sha512-YzePdvd+GcrANTHqDkoNx97YN7EYUGAUrEt4F+h30wD8MEW+QM4EhAHxL3JOUTSkSF0zmwrTyTtSvlGdlqUQiA==" "integrity": "sha512-Ms8ZswqY65/YfcjrlcIwMPD7Rg/dVjdLapMcSHG26W6O67EJDF435ShW4H4LXi1xKO1oRc97tLXUpx8jpLe86A=="
}, },
"node_modules/@next/eslint-plugin-next": { "node_modules/@next/eslint-plugin-next": {
"version": "14.0.4", "version": "14.0.4",
@@ -314,9 +314,9 @@
} }
}, },
"node_modules/@next/swc-darwin-arm64": { "node_modules/@next/swc-darwin-arm64": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.1.tgz",
"integrity": "sha512-MQtCDCP/A4VOuHfTUjZMaSxBwJj5/K+l7ww+W5apI7KutJjtdbAxli1FF6kbgVQST47mdn2mHDsMGhBmt3sjpg==", "integrity": "sha512-JyxnGCS4qT67hdOKQ0CkgFTp+PXub5W1wsGvIq98TNbF3YEIN7iDekYhYsZzc8Ov0pWEsghQt+tANdidITCLaw==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -329,9 +329,9 @@
} }
}, },
"node_modules/@next/swc-darwin-x64": { "node_modules/@next/swc-darwin-x64": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.0.1.tgz",
"integrity": "sha512-H482SA2gpel5FpJDEE2W/L+ZHHcNg1a6tIzluzTmCJ7OTFMgU8/SifGORHHKjKk2eH3oDmbKn8ClXs9UBYQClA==", "integrity": "sha512-625Z7bb5AyIzswF9hvfZWa+HTwFZw+Jn3lOBNZB87lUS0iuCYDHqk3ujuHCkiyPtSC0xFBtYDLcrZ11mF/ap3w==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -344,9 +344,9 @@
} }
}, },
"node_modules/@next/swc-linux-arm64-gnu": { "node_modules/@next/swc-linux-arm64-gnu": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.0.1.tgz",
"integrity": "sha512-Wuyg36CDBFFrWO8gctSHdGQym7f4hSK5cLJxsPjvvzP+tXL4YVR8Gw7Za+mqJFEWmZ8OQRWwp4ZWgLt5GaRsyg==", "integrity": "sha512-iVpn3KG3DprFXzVHM09kvb//4CNNXBQ9NB/pTm8LO+vnnnaObnzFdS5KM+w1okwa32xH0g8EvZIhoB3fI3mS1g==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -359,9 +359,9 @@
} }
}, },
"node_modules/@next/swc-linux-arm64-musl": { "node_modules/@next/swc-linux-arm64-musl": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.0.1.tgz",
"integrity": "sha512-rL+vKUcp8NWv19wQ6VqoQiWKtXc4Eztm1SoD1cjtuyNb1D0tllNADxubvkdzu25VXlolwjJvA6OXAmOZW1NTpw==", "integrity": "sha512-mVsGyMxTLWZXyD5sen6kGOTYVOO67lZjLApIj/JsTEEohDDt1im2nkspzfV5MvhfS7diDw6Rp/xvAQaWZTv1Ww==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -374,9 +374,9 @@
} }
}, },
"node_modules/@next/swc-linux-x64-gnu": { "node_modules/@next/swc-linux-x64-gnu": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.1.tgz",
"integrity": "sha512-hT3XMWZbaArw5/Ri9DyWqXt4hhxsJgAg1QajDnm98uWBQrBWuganRFpmm8VahpNjEIt+qkzQ1c+A8BdQnyQ8+A==", "integrity": "sha512-wMqf90uDWN001NqCM/auRl3+qVVeKfjJdT9XW+RMIOf+rhUzadmYJu++tp2y+hUbb6GTRhT+VjQzcgg/QTD9NQ==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -389,9 +389,9 @@
} }
}, },
"node_modules/@next/swc-linux-x64-musl": { "node_modules/@next/swc-linux-x64-musl": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.1.tgz",
"integrity": "sha512-Z5x1WbyG/oqKaWbpVTCJW+SdB9GQLeC6y1Bmzwzw2P0LY4fzKtho8f+/8iB+cXzpMA0vfj2DWMs7CBgHfbCFpw==", "integrity": "sha512-ol1X1e24w4j4QwdeNjfX0f+Nza25n+ymY0T2frTyalVczUmzkVD7QGgPTZMHfR1aLrO69hBs0G3QBYaj22J5GQ==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -404,9 +404,9 @@
} }
}, },
"node_modules/@next/swc-win32-arm64-msvc": { "node_modules/@next/swc-win32-arm64-msvc": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.0.1.tgz",
"integrity": "sha512-biqb28j9VJUaLKBtGFzbRjpaLWcp/SYCxRmoaK2VZZ97Kycpwp4wKaa8R9gFF+uHq0eqG27LN/NQ6PwuHc+TXQ==", "integrity": "sha512-WEmTEeWs6yRUEnUlahTgvZteh5RJc4sEjCQIodJlZZ5/VJwVP8p2L7l6VhzQhT4h7KvLx/Ed4UViBdne6zpIsw==",
"cpu": [ "cpu": [
"arm64" "arm64"
], ],
@@ -419,9 +419,9 @@
} }
}, },
"node_modules/@next/swc-win32-ia32-msvc": { "node_modules/@next/swc-win32-ia32-msvc": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.0.1.tgz",
"integrity": "sha512-vfvcqfPms3/yoaWhSEQfCsMjtymPEiiaciIo1C263deJOIstZBKuuPe5wv4QnccHoK02i74vjNl5zN1bNJ/eWw==", "integrity": "sha512-oFpHphN4ygAgZUKjzga7SoH2VGbEJXZa/KL8bHCAwCjDWle6R1SpiGOdUdA8EJ9YsG1TYWpzY6FTbUA+iAJeww==",
"cpu": [ "cpu": [
"ia32" "ia32"
], ],
@@ -434,9 +434,9 @@
} }
}, },
"node_modules/@next/swc-win32-x64-msvc": { "node_modules/@next/swc-win32-x64-msvc": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.1.tgz",
"integrity": "sha512-39FcDa/pP7fXL17PB9hIcbMNsfr1ew5RwvZEtKy1+qmuqXA/sApZt3Kbm3D/ggWP/bfHVRhfq5QKp8X4trADjw==", "integrity": "sha512-FFp3nOJ/5qSpeWT0BZQ+YE1pSMk4IMpkME/1DwKBwhg4mJLB9L+6EXuJi4JEwaJdl5iN+UUlmUD3IsR1kx5fAg==",
"cpu": [ "cpu": [
"x64" "x64"
], ],
@@ -4235,15 +4235,14 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/next": { "node_modules/next": {
"version": "14.0.5-canary.12", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/next/-/next-14.0.5-canary.12.tgz", "resolved": "https://registry.npmjs.org/next/-/next-14.0.1.tgz",
"integrity": "sha512-+w3vbb8VRFvDM8NxB5XkqkOmS+Ox9zCi6P+Ww+oolsM5TLMxA8t0sh4y+BETEpFjdwq8BgewFIBk9tudvz5xkA==", "integrity": "sha512-s4YaLpE4b0gmb3ggtmpmV+wt+lPRuGtANzojMQ2+gmBpgX9w5fTbjsy6dXByBuENsdCX5pukZH/GxdFgO62+pA==",
"dependencies": { "dependencies": {
"@next/env": "14.0.5-canary.12", "@next/env": "14.0.1",
"@swc/helpers": "0.5.2", "@swc/helpers": "0.5.2",
"busboy": "1.6.0", "busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406", "caniuse-lite": "^1.0.30001406",
"graceful-fs": "^4.2.11",
"postcss": "8.4.31", "postcss": "8.4.31",
"styled-jsx": "5.1.1", "styled-jsx": "5.1.1",
"watchpack": "2.4.0" "watchpack": "2.4.0"
@@ -4255,15 +4254,15 @@
"node": ">=18.17.0" "node": ">=18.17.0"
}, },
"optionalDependencies": { "optionalDependencies": {
"@next/swc-darwin-arm64": "14.0.5-canary.12", "@next/swc-darwin-arm64": "14.0.1",
"@next/swc-darwin-x64": "14.0.5-canary.12", "@next/swc-darwin-x64": "14.0.1",
"@next/swc-linux-arm64-gnu": "14.0.5-canary.12", "@next/swc-linux-arm64-gnu": "14.0.1",
"@next/swc-linux-arm64-musl": "14.0.5-canary.12", "@next/swc-linux-arm64-musl": "14.0.1",
"@next/swc-linux-x64-gnu": "14.0.5-canary.12", "@next/swc-linux-x64-gnu": "14.0.1",
"@next/swc-linux-x64-musl": "14.0.5-canary.12", "@next/swc-linux-x64-musl": "14.0.1",
"@next/swc-win32-arm64-msvc": "14.0.5-canary.12", "@next/swc-win32-arm64-msvc": "14.0.1",
"@next/swc-win32-ia32-msvc": "14.0.5-canary.12", "@next/swc-win32-ia32-msvc": "14.0.1",
"@next/swc-win32-x64-msvc": "14.0.5-canary.12" "@next/swc-win32-x64-msvc": "14.0.1"
}, },
"peerDependencies": { "peerDependencies": {
"@opentelemetry/api": "^1.1.0", "@opentelemetry/api": "^1.1.0",

View File

@@ -26,7 +26,7 @@
"clsx": "^2.0.0", "clsx": "^2.0.0",
"lucide-react": "^0.290.0", "lucide-react": "^0.290.0",
"nanoid": "^5.0.4", "nanoid": "^5.0.4",
"next": "^14.0.5-canary.12", "next": "^14.0.1",
"next-plausible": "^3.12.0", "next-plausible": "^3.12.0",
"next-themes": "^0.2.1", "next-themes": "^0.2.1",
"next13-progressbar": "^1.1.1", "next13-progressbar": "^1.1.1",

View File

@@ -6,7 +6,7 @@ import {
DialogTitle, DialogTitle,
} from '@/components/ui/dialog' } from '@/components/ui/dialog'
import { useRouter } from 'next/navigation' import { useRouter } from 'next/navigation'
import { ReactNode } from 'react' import { ReactNode, useState } from 'react'
export function ExpenseModal({ export function ExpenseModal({
children, children,
@@ -16,9 +16,16 @@ export function ExpenseModal({
title: ReactNode title: ReactNode
}) { }) {
const router = useRouter() const router = useRouter()
const [open, setOpen] = useState(true)
return ( return (
<Dialog open onOpenChange={() => router.back()}> <Dialog
open={open}
onOpenChange={(open) => {
setOpen(open)
if (!open) router.back()
}}
>
<DialogContent className="w-full max-w-screen-sm"> <DialogContent className="w-full max-w-screen-sm">
<DialogHeader> <DialogHeader>
<DialogTitle>{title}</DialogTitle> <DialogTitle>{title}</DialogTitle>

View File

@@ -1,13 +1,13 @@
'use server' 'use server'
import { createExpense, deleteExpense, updateExpense } from '@/lib/api' import { createExpense, deleteExpense, updateExpense } from '@/lib/api'
import { expenseFormSchema } from '@/lib/schemas' import { expenseFormSchema } from '@/lib/schemas'
import { redirect } from 'next/navigation' import { revalidatePath } from 'next/cache'
export async function createExpenseAction(groupId: string, values: unknown) { export async function createExpenseAction(groupId: string, values: unknown) {
'use server' 'use server'
const expenseFormValues = expenseFormSchema.parse(values) const expenseFormValues = expenseFormSchema.parse(values)
await createExpense(expenseFormValues, groupId) await createExpense(expenseFormValues, groupId)
redirect(`/groups/${groupId}`) revalidatePath(`/groups/${groupId}`, 'layout')
} }
export async function updateExpenseAction( export async function updateExpenseAction(
@@ -18,11 +18,11 @@ export async function updateExpenseAction(
'use server' 'use server'
const expenseFormValues = expenseFormSchema.parse(values) const expenseFormValues = expenseFormSchema.parse(values)
await updateExpense(groupId, expenseId, expenseFormValues) await updateExpense(groupId, expenseId, expenseFormValues)
redirect(`/groups/${groupId}`) revalidatePath(`/groups/${groupId}`, 'layout')
} }
export async function deleteExpenseAction(groupId: string, expenseId: string) { export async function deleteExpenseAction(groupId: string, expenseId: string) {
'use server' 'use server'
await deleteExpense(expenseId) await deleteExpense(expenseId)
redirect(`/groups/${groupId}`) revalidatePath(`/groups/${groupId}`, 'layout')
} }

View File

@@ -1,8 +1,5 @@
'use client' 'use client'
import { redirect, useParams } from 'next/navigation'
export default function NotFound() { export default function NotFound() {
const { groupId } = useParams() return null
console.log('Not found!', { groupId })
redirect(`/groups/${groupId}`)
} }

View File

@@ -37,6 +37,7 @@ export function ReimbursementList({
<Button variant="link" asChild className="-mx-4 -my-3"> <Button variant="link" asChild className="-mx-4 -my-3">
<Link <Link
href={`/groups/${groupId}/expenses/create?reimbursement=yes&from=${reimbursement.from}&to=${reimbursement.to}&amount=${reimbursement.amount}`} href={`/groups/${groupId}/expenses/create?reimbursement=yes&from=${reimbursement.from}&to=${reimbursement.to}&amount=${reimbursement.amount}`}
scroll={false}
> >
Mark as paid Mark as paid
</Link> </Link>

View File

@@ -28,7 +28,7 @@ import {
import { getExpense, getGroup } from '@/lib/api' import { getExpense, getGroup } from '@/lib/api'
import { ExpenseFormValues, expenseFormSchema } from '@/lib/schemas' import { ExpenseFormValues, expenseFormSchema } from '@/lib/schemas'
import { zodResolver } from '@hookform/resolvers/zod' import { zodResolver } from '@hookform/resolvers/zod'
import { useSearchParams } from 'next/navigation' import { useRouter, useSearchParams } from 'next/navigation'
import { useForm } from 'react-hook-form' import { useForm } from 'react-hook-form'
export type Props = { export type Props = {
@@ -61,6 +61,7 @@ export function ExpenseForm({ group, expense }: Props) {
} }
: { title: '', amount: 0, paidFor: [], isReimbursement: false }, : { title: '', amount: 0, paidFor: [], isReimbursement: false },
}) })
const router = useRouter()
return ( return (
<Form {...form}> <Form {...form}>
@@ -71,6 +72,7 @@ export function ExpenseForm({ group, expense }: Props) {
} else { } else {
await createExpenseAction(group.id, values) await createExpenseAction(group.id, values)
} }
router.back()
})} })}
> >
<div className="grid grid-cols-1 sm:grid-cols-2 gap-6"> <div className="grid grid-cols-1 sm:grid-cols-2 gap-6">
@@ -254,7 +256,10 @@ export function ExpenseForm({ group, expense }: Props) {
type="button" type="button"
variant="destructive" variant="destructive"
loadingContent="Deleting…" loadingContent="Deleting…"
action={() => deleteExpenseAction(group.id, expense.id)} action={async () => {
await deleteExpenseAction(group.id, expense.id)
router.back()
}}
> >
Delete Delete
</AsyncButton> </AsyncButton>