import { useForm, useInvalidateAuthStore } from "@refinedev/core";
import { CrudForm } from "../../lib/crud/components/crud-form";
import { empty_user } from "../../providers/auth-provider";

export const CreateFirm = () => {
  const invalidateAuthStore = useInvalidateAuthStore()
  const refreshUser = () => {
    empty_user();
    invalidateAuthStore().then();
  }

  const resourceBasePath = "hub/users";
  const { onFinish } = useForm({
    resource: `${resourceBasePath}/firms`,
    action: "create",
    redirect: "list",
    onMutationSuccess: data => refreshUser()
  });

  return (
    <CrudForm
      schemaName={"Firm"}
      resourceBasePath={resourceBasePath}
      onSubmit={(data: any) => onFinish(data)}
    />
  )
}
