Loading screens & layouts

This commit is contained in:
Sebastien Castiel
2023-12-06 12:22:24 -05:00
parent ed55c696cd
commit 6c4ced0f79
12 changed files with 104 additions and 37 deletions

View File

@@ -4,7 +4,8 @@ import { Expense } from '@prisma/client'
import { v4 as uuidv4 } from 'uuid'
export async function createGroup(groupFormValues: GroupFormValues) {
return getPrisma().group.create({
const prisma = await getPrisma()
return prisma.group.create({
data: {
id: uuidv4(),
name: groupFormValues.name,
@@ -36,7 +37,8 @@ export async function createExpense(
throw new Error(`Invalid participant ID: ${participant}`)
}
return getPrisma().expense.create({
const prisma = await getPrisma()
return prisma.expense.create({
data: {
id: uuidv4(),
groupId,
@@ -73,7 +75,8 @@ export async function updateExpense(
throw new Error(`Invalid participant ID: ${participant}`)
}
return getPrisma().expense.update({
const prisma = await getPrisma()
return prisma.expense.update({
where: { id: expenseId },
data: {
amount: expenseFormValues.amount,
@@ -104,7 +107,8 @@ export async function updateGroup(
const existingGroup = await getGroup(groupId)
if (!existingGroup) throw new Error('Invalid group ID')
return getPrisma().group.update({
const prisma = await getPrisma()
return prisma.group.update({
where: { id: groupId },
data: {
name: groupFormValues.name,
@@ -134,21 +138,24 @@ export async function updateGroup(
}
export async function getGroup(groupId: string) {
return getPrisma().group.findUnique({
const prisma = await getPrisma()
return prisma.group.findUnique({
where: { id: groupId },
include: { participants: true },
})
}
export async function getGroupExpenses(groupId: string) {
return getPrisma().expense.findMany({
const prisma = await getPrisma()
return prisma.expense.findMany({
where: { groupId },
include: { paidFor: { include: { participant: true } }, paidBy: true },
})
}
export async function getExpense(groupId: string, expenseId: string) {
return getPrisma().expense.findUnique({
const prisma = await getPrisma()
return prisma.expense.findUnique({
where: { id: expenseId },
include: { paidBy: true, paidFor: true },
})

View File

@@ -2,7 +2,7 @@ import { PrismaClient } from '@prisma/client'
let prisma: PrismaClient
export function getPrisma() {
export async function getPrisma() {
if (!prisma) {
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()

View File

@@ -1,6 +1,10 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
import { clsx, type ClassValue } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}