import { UseQueryResult } from "@tanstack/react-query" import { validateMezoId, MezoId } from "../utils/mezoId" import { useGetAccountByMezoId } from "./useGetAccountByMezoId" export function useValidateMezoId(mezoId: MezoId) { const validationErrors = validateMezoId(mezoId) return useGetAccountByMezoId(mezoId, { placeholderData: { // @ts-expect-error TODO: Couldn't fix type for placeholderData which for // some reason should return the same data as the data returned in // queryFn. isValid: validationErrors.length === 0, isAvailable: validationErrors.length === 0, errors: validationErrors, }, enabled: validationErrors.length === 0, // @ts-expect-error TODO: Couldn't fix type for select which for some reason // should return the same data as the data returned in queryFn. select: (data) => { const isValid = validationErrors.length === 0 const isAvailable = isValid ? !data : false return { isValid, isAvailable, errors: validationErrors } }, }) as UseQueryResult<{ isValid: boolean isAvailable: boolean errors: string[] }> }