Skip to content

Commit f7bed72

Browse files
authored
fix(admin_ui): kyc update rerender issue (#1306)
1 parent c3ded99 commit f7bed72

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

ui/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/src/pages/organizations/details/index.tsx

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useCallback, useEffect, useState } from "react";
2-
import { useQuery } from "@connectrpc/connect-query";
1+
import { useCallback, useEffect, useMemo, useState } from "react";
2+
import { useQuery, createConnectQueryKey, useTransport } from "@connectrpc/connect-query";
33
import { Outlet, useParams } from "react-router-dom";
44

55
import { OrganizationDetailsLayout } from "./layout";
@@ -17,6 +17,7 @@ export const OrganizationDetails = () => {
1717
const [searchQuery, setSearchQuery] = useState("");
1818

1919
const { organizationId } = useParams();
20+
const transport = useTransport();
2021

2122
// Use Connect RPC for fetching organization
2223
const {
@@ -43,22 +44,28 @@ export const OrganizationDetails = () => {
4344

4445
// Fetch KYC details
4546
const {
46-
data: kycDetails,
47+
data: kycData,
4748
isLoading: isKYCLoading,
4849
error: kycError,
4950
} = useQuery(
5051
FrontierServiceQueries.getOrganizationKyc,
5152
{ orgId: organizationId || "" },
5253
{
5354
enabled: !!organizationId,
54-
select: (data) => data?.organizationKyc,
5555
},
5656
);
5757

58+
const kycDetails = useMemo(() => kycData?.organizationKyc, [kycData]);
59+
5860
function updateKYCDetails(kyc: typeof kycDetails) {
5961
if (!organizationId) return;
6062
queryClient.setQueryData(
61-
[FrontierServiceQueries.getOrganizationKyc, { orgId: organizationId }],
63+
createConnectQueryKey({
64+
schema: FrontierServiceQueries.getOrganizationKyc,
65+
transport,
66+
input: { orgId: organizationId },
67+
cardinality: "finite",
68+
}),
6269
{ organizationKyc: kyc },
6370
);
6471
}
@@ -118,17 +125,15 @@ export const OrganizationDetails = () => {
118125
);
119126

120127
// Fetch billing accounts list
121-
const {
122-
data: firstBillingAccountId = "",
123-
error: billingAccountsError,
124-
} = useQuery(
125-
FrontierServiceQueries.listBillingAccounts,
126-
{ orgId: organizationId || "" },
127-
{
128-
enabled: !!organizationId,
129-
select: (data) => data?.billingAccounts?.[0]?.id || "",
130-
},
131-
);
128+
const { data: firstBillingAccountId = "", error: billingAccountsError } =
129+
useQuery(
130+
FrontierServiceQueries.listBillingAccounts,
131+
{ orgId: organizationId || "" },
132+
{
133+
enabled: !!organizationId,
134+
select: (data) => data?.billingAccounts?.[0]?.id || "",
135+
},
136+
);
132137

133138
// Fetch billing account details
134139
const {
@@ -160,7 +165,7 @@ export const OrganizationDetails = () => {
160165
data: tokenBalance = "0",
161166
isLoading: isTokenBalanceLoading,
162167
error: tokenBalanceError,
163-
refetch: fetchTokenBalance
168+
refetch: fetchTokenBalance,
164169
} = useQuery(
165170
FrontierServiceQueries.getBillingBalance,
166171
{
@@ -194,7 +199,10 @@ export const OrganizationDetails = () => {
194199
console.error("Failed to fetch billing accounts:", billingAccountsError);
195200
}
196201
if (billingAccountError) {
197-
console.error("Failed to fetch billing account details:", billingAccountError);
202+
console.error(
203+
"Failed to fetch billing account details:",
204+
billingAccountError,
205+
);
198206
}
199207
if (tokenBalanceError) {
200208
console.error("Failed to fetch token balance:", tokenBalanceError);

0 commit comments

Comments
 (0)