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 (
{/* Input Section */}
{/* Button Section */}
{" "} {errors.spridSearchText && (

{errors.spridSearchText.message}

)}
{/* ---- Organization list ---- */} {isLoading ? ( ) : data && data?.data.length > 0 ? (
{data.data.map((org) => (
logo
{org.name}
SPRID :{" "} {org.sprid}
Address:
{org.address}
{" "}
))}
) : SPRID ? (
No organization found for "{SPRID}"
) : null}
Do not have SPRID or could not find organization ?
{/* ---- Footer buttons ---- */}
{flowType !== "default" && ( )}
); }; export default OrgPickerFromSPId;