2025-09-21 12:03:29 +01:00
|
|
|
'use client';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
import { useFormStatus } from 'react-dom';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
import { LoaderIcon } from '@/components/icons';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
2025-09-21 12:03:29 +01:00
|
|
|
import { Button } from './ui/button';
|
2024-10-11 18:00:22 +05:30
|
|
|
|
2024-11-08 17:59:06 +03:00
|
|
|
export function SubmitButton({
|
|
|
|
|
children,
|
|
|
|
|
isSuccessful,
|
|
|
|
|
}: {
|
|
|
|
|
children: React.ReactNode;
|
|
|
|
|
isSuccessful: boolean;
|
|
|
|
|
}) {
|
2024-10-11 18:00:22 +05:30
|
|
|
const { pending } = useFormStatus();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
2025-09-21 12:03:29 +01:00
|
|
|
type={pending ? 'button' : 'submit'}
|
2024-11-08 17:59:06 +03:00
|
|
|
aria-disabled={pending || isSuccessful}
|
2025-09-20 12:47:10 -07:00
|
|
|
disabled={pending || isSuccessful}
|
2025-09-21 12:03:29 +01:00
|
|
|
className="relative"
|
2024-10-11 18:00:22 +05:30
|
|
|
>
|
|
|
|
|
{children}
|
2024-11-08 17:59:06 +03:00
|
|
|
|
|
|
|
|
{(pending || isSuccessful) && (
|
2025-09-09 15:44:07 -04:00
|
|
|
<span className="absolute right-4 animate-spin">
|
2024-10-11 18:00:22 +05:30
|
|
|
<LoaderIcon />
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2024-11-08 17:59:06 +03:00
|
|
|
|
2024-11-15 12:18:17 -05:00
|
|
|
<output aria-live="polite" className="sr-only">
|
2025-09-21 12:03:29 +01:00
|
|
|
{pending || isSuccessful ? 'Loading' : 'Submit form'}
|
2024-11-15 12:18:17 -05:00
|
|
|
</output>
|
2024-10-11 18:00:22 +05:30
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
}
|