feat(form): add loading state and replace custom switch component

This commit introduces a loading state for form submissions and replaces the custom switch component with a third-party library for improved user experience and maintainability.

- Adds `react-switch` as a dependency to replace the custom-built switch component, providing a more robust and feature-rich solution.
- Implements a loading indicator on form submission buttons and in the confirmation modal by utilizing the `useIsMutating` hook from TanStack Query. This provides clear visual feedback to the user during asynchronous operations.
- Creates a reusable `FormFooter` component to encapsulate the submit and cancel buttons, centralizing the form submission logic and loading state.
- Refactors the company create/edit forms to use the new `FormFooter` and `react-switch` components.
- Moves the `BreadcrumbItem` type to a shared types file for better code organization.
This commit is contained in:
AmirReza Jamali
2025-09-20 16:13:04 +03:30
parent 2c43e945c2
commit e6493f5d83
27 changed files with 782 additions and 84 deletions
+16 -2
View File
@@ -1,12 +1,15 @@
import { CheckIcon, XIcon } from "@/assets/icons";
import { cn } from "@/lib/utils";
import { useId } from "react";
import { ChangeEvent, ToggleEvent, useId } from "react";
type PropsType = {
withIcon?: boolean;
background?: "dark" | "light";
backgroundSize?: "sm" | "default";
name?: string;
checked?: boolean;
onToggle: (e: ToggleEvent<HTMLInputElement>) => void;
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
};
export function Switch({
@@ -14,6 +17,9 @@ export function Switch({
withIcon,
backgroundSize,
name,
checked = false,
onToggle,
onChange,
}: PropsType) {
const id = useId();
@@ -23,7 +29,15 @@ export function Switch({
className="flex max-w-fit cursor-pointer select-none items-center"
>
<div className="relative">
<input type="checkbox" name={name} id={id} className="peer sr-only" />
<input
type="checkbox"
name={name}
onToggle={onToggle}
onChange={onChange}
id={id}
className="peer sr-only"
checked={checked}
/>
<div
className={cn("h-8 w-14 rounded-full bg-gray-3 dark:bg-[#5A616B]", {
"h-5": backgroundSize === "sm",