import { useState } from "react"; import { useAssignOrgToTenant, useOrganizationBySPRID, useOrganizationModal, } from "../../hooks/useOrganization"; import Label from "../common/Label"; import { useDebounce } from "../../utils/appUtils"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { spridSchema } from "./OrganizationSchema"; import { OrgCardSkeleton } from "./OrganizationSkeleton"; import { useQueryClient } from "@tanstack/react-query"; // Zod schema: only allow exactly 4 digits const OrgPickerFromSPId = ({ title, placeholder }) => { const { onClose, startStep, flowType, onOpen, prevStep, orgData } = useOrganizationModal(); const clientQuery = useQueryClient(); const { register, handleSubmit, formState: { errors }, watch, } = useForm({ resolver: zodResolver(spridSchema), defaultValues: { spridSearchText: "" }, }); const [SPRID, setSPRID] = useState(""); const { data, isLoading, isError, error, refetch } = useOrganizationBySPRID(SPRID); const onSubmit = (formdata) => { setSPRID(formdata.spridSearchText); }; const handleCrateOrg = () => { clientQuery.removeQueries({ queryKey: ["organization"] }); onOpen({ startStep: 4, orgData: null }); }; const SP = watch("spridSearchText"); return (
{errors.spridSearchText.message}
)}