From 6c4ced0f79f801d85da5e4973ae4154f01b04dba Mon Sep 17 00:00:00 2001
From: Sebastien Castiel <sebastien@castiel.me>
Date: Wed, 6 Dec 2023 12:22:24 -0500
Subject: Loading screens & layouts

---
 src/components/submit-button.tsx | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 src/components/submit-button.tsx

(limited to 'src/components/submit-button.tsx')

diff --git a/src/components/submit-button.tsx b/src/components/submit-button.tsx
new file mode 100644
index 0000000..7489c6c
--- /dev/null
+++ b/src/components/submit-button.tsx
@@ -0,0 +1,23 @@
+import { Button } from '@/components/ui/button'
+import { Loader2 } from 'lucide-react'
+import { PropsWithChildren, ReactNode } from 'react'
+import { useFormState } from 'react-hook-form'
+
+type Props = PropsWithChildren<{
+  loadingContent: ReactNode
+}>
+
+export function SubmitButton({ children, loadingContent }: Props) {
+  const { isSubmitting } = useFormState()
+  return (
+    <Button type="submit" disabled={isSubmitting}>
+      {isSubmitting ? (
+        <>
+          <Loader2 className="w-4 h-4 mr-2 animate-spin" /> {loadingContent}
+        </>
+      ) : (
+        children
+      )}
+    </Button>
+  )
+}
-- 
cgit v1.3

