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

View File

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

View File

@@ -6,7 +6,7 @@ import {
DialogTitle,
} from '@/components/ui/dialog'
import { useRouter } from 'next/navigation'
import { ReactNode } from 'react'
import { ReactNode, useState } from 'react'
export function ExpenseModal({
children,
@@ -16,9 +16,16 @@ export function ExpenseModal({
title: ReactNode
}) {
const router = useRouter()
const [open, setOpen] = useState(true)
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">
<DialogHeader>
<DialogTitle>{title}</DialogTitle>

View File

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

View File

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

View File

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

View File

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