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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user