Skip to content

Commit

Permalink
Add cancel button on expense form (fixes #92)
Browse files Browse the repository at this point in the history
  • Loading branch information
scastiel committed Feb 14, 2024
1 parent f7a13a0 commit 50525ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/components/expense-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ExpenseFormValues, expenseFormSchema } from '@/lib/schemas'
import { cn } from '@/lib/utils'
import { zodResolver } from '@hookform/resolvers/zod'
import { Save, Trash2 } from 'lucide-react'
import Link from 'next/link'
import { useSearchParams } from 'next/navigation'
import { useState } from 'react'
import { useForm } from 'react-hook-form'
Expand Down Expand Up @@ -583,6 +584,9 @@ export function ExpenseForm({
Delete
</AsyncButton>
)}
<Button variant="ghost" asChild>
<Link href={`/groups/${group.id}`}>Cancel</Link>
</Button>
</div>
</form>
</Form>
Expand Down
21 changes: 14 additions & 7 deletions src/components/group-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { getGroup } from '@/lib/api'
import { GroupFormValues, groupFormSchema } from '@/lib/schemas'
import { zodResolver } from '@hookform/resolvers/zod'
import { Save, Trash2 } from 'lucide-react'
import Link from 'next/link'
import { useEffect, useState } from 'react'
import { useFieldArray, useForm } from 'react-hook-form'

Expand Down Expand Up @@ -272,13 +273,19 @@ export function GroupForm({
</CardContent>
</Card>

<SubmitButton
size="lg"
loadingContent={group ? 'Saving…' : 'Creating…'}
onClick={updateActiveUser}
>
<Save className="w-4 h-4 mr-2" /> {group ? <>Save</> : <> Create</>}
</SubmitButton>
<div className="flex mt-4 gap-2">
<SubmitButton
loadingContent={group ? 'Saving…' : 'Creating…'}
onClick={updateActiveUser}
>
<Save className="w-4 h-4 mr-2" /> {group ? <>Save</> : <> Create</>}
</SubmitButton>
{!group && (
<Button variant="ghost" asChild>
<Link href="/groups">Cancel</Link>
</Button>
)}
</div>
</form>
</Form>
)
Expand Down

0 comments on commit 50525ad

Please sign in to comment.