Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix useGroups

Steven Tey762369aa0443
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/use-commission-filters.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/use-commission-filters.tsx
index 3f87d84e83..b6df8002e7 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/use-commission-filters.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/use-commission-filters.tsx
@@ -35,13 +35,7 @@ export function useCommissionFilters() {
selectedFilter === "customerId" ? debouncedSearch : "",
);
- const { groups } = useGroups({
- // here we're coercing page to 1 to make sure the partner table pagination doesn't mess with this
- // TODO: standardize how we handle params in useSWR hooks – it's a bit all over the place rn
- query: {
- page: 1,
- },
- });
+ const { groups } = useGroups();
const filters = useMemo(
() => [
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/groups-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/groups-table.tsx
index bc257483a1..25f22981f2 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/groups-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/groups/groups-table.tsx
@@ -50,6 +50,7 @@ export function GroupsTable() {
query: {
includeExpandedFields: true,
},
+ includeParams: true,
});
const {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
index 371f641a7d..1870b838d6 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
@@ -141,13 +141,7 @@ export function PartnersTable() {
partnerId: detailsSheetState.partnerId,
});
- const { groups } = useGroups({
- // here we're coercing page to 1 to make sure the partner table pagination doesn't mess with this
- // TODO: standardize how we handle params in useSWR hooks – it's a bit all over the place rn
- query: {
- page: 1,
- },
- });
+ const { groups } = useGroups();
const [pendingChangeGroupPartners, setPendingChangeGroupPartners] = useState<
EnrolledPartnerProps[]
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx
index 1d1452b911..e23954c385 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/use-partner-filters.tsx
@@ -12,13 +12,7 @@ export function usePartnerFilters(extraSearchParams: Record<string, string>) {
const { searchParamsObj, queryParams } = useRouterStuff();
const { id: workspaceId, slug } = useWorkspace();
- const { groups } = useGroups({
- // here we're coercing page to 1 to make sure the partner table pagination doesn't mess with this
- // TODO: standardize how we handle params in useSWR hooks – it's a bit all over the place rn
- query: {
- page: 1,
- },
- });
+ const { groups } = useGroups();
const { partnersCount: countriesCount } = usePartnersCount<
| {
diff --git a/apps/web/lib/swr/use-groups.ts b/apps/web/lib/swr/use-groups.ts
index 13bcb7c7b4..b086788a4a 100644
--- a/apps/web/lib/swr/use-groups.ts
+++ b/apps/web/lib/swr/use-groups.ts
@@ -10,24 +10,31 @@ const partialQuerySchema = getGroupsQuerySchema.partial();
export default function useGroups<T extends GroupProps>({
query,
+ includeParams,
}: {
query?: z.infer<typeof partialQuerySchema>;
+ includeParams?: boolean;
} = {}) {
const { id: workspaceId, defaultProgramId } = useWorkspace();
const { getQueryString } = useRouterStuff();
const { data, isLoading, error } = useSWR<T[]>(
defaultProgramId
- ? `/api/groups${getQueryString(
- {
- workspaceId,
- sortBy: "saleAmount",
- ...query,
- },
- {
- exclude: ["partnerId"],
- },
- )}`
+ ? `/api/groups${
+ // TODO: standardize how we handle params in useSWR hooks – it's a bit all over the place rn
+ includeParams
+ ? getQueryString(
+ {
+ workspaceId,
+ sortBy: "saleAmount",
+ ...query,
+ },
+ {
+ exclude: ["partnerId"],
+ },
+ )
+ : `?workspaceId=${workspaceId}`
+ }`
: null,
fetcher,
{
diff --git a/apps/web/ui/partners/change-group-modal.tsx b/apps/web/ui/partners/change-group-modal.tsx
index f8ab94e5cf..92fc50c38a 100644
--- a/apps/web/ui/partners/change-group-modal.tsx
+++ b/apps/web/ui/partners/change-group-modal.tsx
@@ -8,6 +8,7 @@ import {
Dispatch,
SetStateAction,
useCallback,
+ useEffect,
useMemo,
useState,
} from "react";
@@ -27,6 +28,12 @@ function ChangeGroupModal({
const [selectedGroupId, setSelectedGroupId] = useState<string | null>(null);
+ useEffect(() => {
+ if (partners.length === 1) {
+ setSelectedGroupId(partners[0].groupId ?? null);
+ }
+ }, [partners]);
+
const { makeRequest: changeGroup, isSubmitting } = useApiMutation();
const handleChangeGroup = useCallback(async () => {
diff --git a/apps/web/ui/partners/partner-details-sheet.tsx b/apps/web/ui/partners/partner-details-sheet.tsx
index c49d7fe609..3d9333b76f 100644
--- a/apps/web/ui/partners/partner-details-sheet.tsx
+++ b/apps/web/ui/partners/partner-details-sheet.tsx
@@ -49,14 +49,7 @@ function PartnerDetailsSheetContent({ partner }: PartnerDetailsSheetProps) {
const { slug } = useWorkspace();
const [tab, setTab] = useState<Tab>("links");
- const { groups } = useGroups({
- query: {
- groupIds: partner.groupId ? [partner.groupId] : undefined,
- // here we're coercing page to 1 to make sure the partner table pagination doesn't mess with this
- // TODO: standardize how we handle params in useSWR hooks – it's a bit all over the place rn
- page: 1,
- },
- });
+ const { groups } = useGroups();
const group = groups?.find((g) => g.id === partner.groupId);