feat: Add button loading states

This commit is contained in:
gpt-engineer-app[bot]
2025-11-04 18:11:31 +00:00
parent 2deab69ebe
commit 6b5be8a70b
11 changed files with 98 additions and 23 deletions

View File

@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button';
import type { RideModelTechnicalSpec } from '@/types/database';
import { getErrorMessage } from '@/lib/errorHandler';
import { handleError } from '@/lib/errorHandler';
import { toast } from 'sonner';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { Label } from '@/components/ui/label';
@@ -71,6 +72,7 @@ export function RideModelForm({
initialData
}: RideModelFormProps) {
const { isModerator } = useUserRole();
const [isSubmitting, setIsSubmitting] = useState(false);
const [technicalSpecs, setTechnicalSpecs] = useState<{
spec_name: string;
spec_value: string;
@@ -101,14 +103,16 @@ export function RideModelForm({
});
const handleFormSubmit = (data: RideModelFormData) => {
const handleFormSubmit = async (data: RideModelFormData) => {
setIsSubmitting(true);
try {
// Include relational technical specs with extended type
onSubmit({
await onSubmit({
...data,
manufacturer_id: manufacturerId,
_technical_specifications: technicalSpecs
});
toast.success('Ride model submitted for review');
} catch (error: unknown) {
handleError(error, {
action: initialData?.id ? 'Update Ride Model' : 'Create Ride Model'
@@ -116,6 +120,8 @@ export function RideModelForm({
// Re-throw so parent can handle modal closing
throw error;
} finally {
setIsSubmitting(false);
}
};
@@ -294,12 +300,15 @@ export function RideModelForm({
type="button"
variant="outline"
onClick={onCancel}
disabled={isSubmitting}
>
<X className="w-4 h-4 mr-2" />
Cancel
</Button>
<Button
type="submit"
loading={isSubmitting}
loadingText="Saving..."
>
<Save className="w-4 h-4 mr-2" />
Save Model