mirror of
https://github.com/spliit-app/spliit.git
synced 2026-02-26 09:26:12 +01:00
Add currency
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Group" ADD COLUMN "currency" TEXT NOT NULL DEFAULT '$';
|
||||||
@@ -14,6 +14,7 @@ datasource db {
|
|||||||
model Group {
|
model Group {
|
||||||
id String @id
|
id String @id
|
||||||
name String
|
name String
|
||||||
|
currency String @default("$")
|
||||||
participants Participant[]
|
participants Participant[]
|
||||||
expenses Expense[]
|
expenses Expense[]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ export default async function GroupPage({
|
|||||||
</Badge>
|
</Badge>
|
||||||
))}
|
))}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-right tabular-nums">
|
<TableCell className="text-right tabular-nums whitespace-nowrap">
|
||||||
$ {expense.amount.toFixed(2)}
|
{group.currency} {expense.amount.toFixed(2)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -118,16 +118,19 @@ export function ExpenseForm({ group, expense, onSubmit, onDelete }: Props) {
|
|||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="order-2 sm:order-3">
|
<FormItem className="order-2 sm:order-3">
|
||||||
<FormLabel>Amount</FormLabel>
|
<FormLabel>Amount</FormLabel>
|
||||||
<FormControl>
|
<div className="flex items-baseline gap-2">
|
||||||
<Input
|
<span>{group.currency}</span>
|
||||||
className="text-base"
|
<FormControl>
|
||||||
type="number"
|
<Input
|
||||||
min={0.01}
|
className="text-base max-w-[120px]"
|
||||||
step={0.01}
|
type="number"
|
||||||
placeholder="0.00"
|
min={0.01}
|
||||||
{...field}
|
step={0.01}
|
||||||
/>
|
placeholder="0.00"
|
||||||
</FormControl>
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</div>
|
||||||
<FormDescription>Enter the expense amount.</FormDescription>
|
<FormDescription>Enter the expense amount.</FormDescription>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|||||||
@@ -36,10 +36,12 @@ export function GroupForm({ group, onSubmit }: Props) {
|
|||||||
defaultValues: group
|
defaultValues: group
|
||||||
? {
|
? {
|
||||||
name: group.name,
|
name: group.name,
|
||||||
|
currency: group.currency,
|
||||||
participants: group.participants,
|
participants: group.participants,
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
name: '',
|
name: '',
|
||||||
|
currency: '',
|
||||||
participants: [{ name: 'John' }, { name: 'Jane' }, { name: 'Jack' }],
|
participants: [{ name: 'John' }, { name: 'Jane' }, { name: 'Jack' }],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -60,7 +62,7 @@ export function GroupForm({ group, onSubmit }: Props) {
|
|||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Group information</CardTitle>
|
<CardTitle>Group information</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="name"
|
name="name"
|
||||||
@@ -81,6 +83,28 @@ export function GroupForm({ group, onSubmit }: Props) {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="currency"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Currency symbol</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
className="text-base"
|
||||||
|
placeholder="$, €, £…"
|
||||||
|
max={5}
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
We’ll used it to display amounts.
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
<Card>
|
<Card>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export async function createGroup(groupFormValues: GroupFormValues) {
|
|||||||
data: {
|
data: {
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
name: groupFormValues.name,
|
name: groupFormValues.name,
|
||||||
|
currency: groupFormValues.currency,
|
||||||
participants: {
|
participants: {
|
||||||
createMany: {
|
createMany: {
|
||||||
data: groupFormValues.participants.map(({ name }) => ({
|
data: groupFormValues.participants.map(({ name }) => ({
|
||||||
@@ -120,6 +121,7 @@ export async function updateGroup(
|
|||||||
where: { id: groupId },
|
where: { id: groupId },
|
||||||
data: {
|
data: {
|
||||||
name: groupFormValues.name,
|
name: groupFormValues.name,
|
||||||
|
currency: groupFormValues.currency,
|
||||||
participants: {
|
participants: {
|
||||||
deleteMany: existingGroup.participants.filter(
|
deleteMany: existingGroup.participants.filter(
|
||||||
(p) => !groupFormValues.participants.some((p2) => p2.id === p.id),
|
(p) => !groupFormValues.participants.some((p2) => p2.id === p.id),
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ export const groupFormSchema = z
|
|||||||
.string()
|
.string()
|
||||||
.min(2, 'Enter at least two characters.')
|
.min(2, 'Enter at least two characters.')
|
||||||
.max(50, 'Enter at most 50 characters.'),
|
.max(50, 'Enter at most 50 characters.'),
|
||||||
|
currency: z
|
||||||
|
.string()
|
||||||
|
.min(1, 'Enter at least one character.')
|
||||||
|
.max(5, 'Enter at most five characters.'),
|
||||||
participants: z
|
participants: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
|
|||||||
Reference in New Issue
Block a user