Fix toast and data reset issues

- Resolved issue where budget creation toast appeared before expense creation toast.
- Fixed data reset causing a redirect to the login screen.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-16 09:13:08 +00:00
parent 468bb79c9e
commit 7ab79d125e
6 changed files with 213 additions and 240 deletions

View File

@@ -4,6 +4,7 @@ import { useForm } from 'react-hook-form';
import { Form, FormField, FormItem, FormLabel } from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { Loader2 } from 'lucide-react';
import ExpenseCategorySelector from './ExpenseCategorySelector';
export interface ExpenseFormValues {
@@ -15,9 +16,10 @@ export interface ExpenseFormValues {
interface ExpenseFormProps {
onSubmit: (data: ExpenseFormValues) => void;
onCancel: () => void;
isSubmitting?: boolean;
}
const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel }) => {
const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel, isSubmitting = false }) => {
const form = useForm<ExpenseFormValues>({
defaultValues: {
title: '',
@@ -47,7 +49,11 @@ const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel }) => {
render={({ field }) => (
<FormItem>
<FormLabel></FormLabel>
<Input placeholder="지출 내역을 입력하세요" {...field} />
<Input
placeholder="지출 내역을 입력하세요"
{...field}
disabled={isSubmitting}
/>
</FormItem>
)}
/>
@@ -62,6 +68,7 @@ const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel }) => {
placeholder="금액을 입력하세요"
value={field.value}
onChange={handleAmountChange}
disabled={isSubmitting}
/>
</FormItem>
)}
@@ -75,7 +82,8 @@ const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel }) => {
<FormLabel></FormLabel>
<ExpenseCategorySelector
value={field.value}
onValueChange={(value) => field.onChange(value)}
onValueChange={(value) => field.onChange(value)}
disabled={isSubmitting}
/>
</FormItem>
)}
@@ -86,14 +94,21 @@ const ExpenseForm: React.FC<ExpenseFormProps> = ({ onSubmit, onCancel }) => {
type="button"
variant="outline"
onClick={onCancel}
disabled={isSubmitting}
>
</Button>
<Button
type="submit"
className="bg-neuro-income text-white hover:bg-neuro-income/90"
disabled={isSubmitting}
>
{isSubmitting ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
...
</>
) : '저장'}
</Button>
</div>
</form>