diff --git a/apps/console/src/components/form/ThirdPartiesMultiSelectField.tsx b/apps/console/src/components/form/ThirdPartiesMultiSelectField.tsx index 581d00f60..88260e2a4 100644 --- a/apps/console/src/components/form/ThirdPartiesMultiSelectField.tsx +++ b/apps/console/src/components/form/ThirdPartiesMultiSelectField.tsx @@ -15,16 +15,38 @@ import { faviconUrl } from "@probo/helpers"; import { useTranslate } from "@probo/i18n"; import { Avatar, Badge, Button, Field, IconCrossLargeX, Option, Select } from "@probo/ui"; -import { type ComponentProps, Suspense, useState } from "react"; +import { type ComponentProps, Suspense, useEffect, useState } from "react"; import { type Control, Controller, type FieldValues, type Path } from "react-hook-form"; +import { type PreloadedQuery, usePreloadedQuery, useQueryLoader } from "react-relay"; +import { graphql } from "relay-runtime"; -import { useThirdParties } from "#/hooks/graph/ThirdPartyGraph"; +import type { ThirdPartiesMultiSelectFieldQuery } from "#/__generated__/core/ThirdPartiesMultiSelectFieldQuery.graphql"; + +const thirdPartiesQuery = graphql` + query ThirdPartiesMultiSelectFieldQuery($organizationId: ID!) { + organization: node(id: $organizationId) { + ... on Organization { + thirdParties( + first: 100 + orderBy: { direction: ASC, field: NAME } + ) { + edges { + node { + id + name + websiteUrl + } + } + } + } + } + } +`; type ThirdParty = { id: string; name: string; websiteUrl: string | null | undefined; - level?: number; }; type Props = { @@ -42,29 +64,47 @@ export function ThirdPartiesMultiSelectField) { + const [queryRef, loadQuery] + = useQueryLoader(thirdPartiesQuery); + + useEffect(() => { + loadQuery({ organizationId }, { fetchPolicy: "network-only" }); + }, [loadQuery, organizationId]); + + const loadingState = ( +