import React from "react" import { useForm } from "react-hook-form" import { faCheckDouble, faExclamationTriangle, faCheck } from "@fortawesome/free-solid-svg-icons" import { LoadingButton } from "@mui/lab" import { IconDefinition } from "@fortawesome/fontawesome-common-types" import { size } from "lodash" import { Icon } from "../icon" import { FormState } from "./types" interface IFormSubmitProps { form: ReturnType label: string state: FormState icon?: IconDefinition disabled?: boolean } export function FormSubmit({ form, icon, label, state, disabled }: IFormSubmitProps) { const { formState: { errors, isSubmitting, isValidating } } = form const isValid = size(errors) === 0 let color let iconEl if (!isValid) { color = "warning" iconEl = } else { switch (state) { case "error": color = "error" iconEl = break case "success": color = "success" iconEl = break case "normal": default: color = "primary" iconEl = } } return {label} }