Skip to content

Commit f227999

Browse files
authored
Merge pull request #1079 from cultuurnet/feature/III-6713
III-6713 - Change logic of recent used organizers on dashboard
2 parents 3877b81 + bb2fea2 commit f227999

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/pages/dashboard/index.page.tsx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useRouter } from 'next/router';
44
import React, { ComponentType, useMemo, useState } from 'react';
55
import { Cookies } from 'react-cookie';
66
import { Trans, useTranslation } from 'react-i18next';
7-
import { useQueryClient, UseQueryResult } from 'react-query';
7+
import { useQueryClient } from 'react-query';
88
import { dehydrate } from 'react-query/hydration';
99

1010
import { CalendarType } from '@/constants/CalendarType';
@@ -15,12 +15,12 @@ import {
1515
useDeleteEventByIdMutation,
1616
useGetEventsByCreatorQuery,
1717
} from '@/hooks/api/events';
18+
import { useGetOffersByCreatorQuery } from '@/hooks/api/offers';
1819
import {
1920
prefetchGetOrganizersByCreatorQuery,
2021
useDeleteOrganizerByIdMutation,
2122
useGetOrganizersByCreatorQuery,
2223
useGetOrganizersByQueryQuery,
23-
useGetSuggestedOrganizersQuery,
2424
} from '@/hooks/api/organizers';
2525
import {
2626
prefetchGetPlacesByCreatorQuery,
@@ -47,7 +47,6 @@ import { Alert, AlertVariants } from '@/ui/Alert';
4747
import { Box } from '@/ui/Box';
4848
import { Button, ButtonVariants } from '@/ui/Button';
4949
import { Dropdown } from '@/ui/Dropdown';
50-
import { Icons } from '@/ui/Icon';
5150
import type { InlineProps } from '@/ui/Inline';
5251
import { getInlineProps, Inline } from '@/ui/Inline';
5352
import { LabelPositions } from '@/ui/Label';
@@ -224,11 +223,6 @@ const OfferRow = ({ item: offer, onDelete, ...props }: OfferRowProps) => {
224223
? t(`eventTypes*${typeId}`, { keySeparator: '*' })
225224
: undefined;
226225

227-
const period =
228-
offer.calendarSummary?.[i18n.language]?.text?.[
229-
offer.calendarType === CalendarType.SINGLE ? 'lg' : 'sm'
230-
];
231-
232226
const rowStatus = useMemo<RowStatus>(() => {
233227
if (isPlanned) {
234228
return 'PLANNED';
@@ -580,21 +574,42 @@ const Dashboard = (): any => {
580574
);
581575
};
582576

583-
const suggestedOrganizerIds = useGetSuggestedOrganizersQuery(
584-
{},
577+
const getOffersByCreatorQuery = useGetOffersByCreatorQuery(
578+
{
579+
advancedQuery: '_exists_:organizer.id',
580+
creator: user,
581+
paginationOptions: { start: 0, limit: 30 },
582+
},
585583
{ enabled: tab === 'organizers' },
586584
);
587585

588-
suggestedOrganizerIds.data;
586+
const recentUsedOrganizers = useMemo(() => {
587+
const recentOrganizers: Organizer[] = [];
588+
589+
getOffersByCreatorQuery.data?.member.forEach((event) => {
590+
if (
591+
event.organizer &&
592+
!recentOrganizers.some(
593+
(recentOrganizer) =>
594+
recentOrganizer['@id'] === event.organizer['@id'],
595+
)
596+
)
597+
recentOrganizers.push(event.organizer);
598+
});
599+
600+
return recentOrganizers.slice(0, 10);
601+
}, [getOffersByCreatorQuery.data?.member]);
589602

590603
const suggestedOrganizers = useGetOrganizersByQueryQuery(
591604
{
592-
q: suggestedOrganizerIds.data?.member
593-
.map((result) => `id:${parseOfferId(result['@id'])}`)
594-
.join(' OR '),
605+
q:
606+
recentUsedOrganizers
607+
.map((organizer) => `id:${parseOfferId(organizer['@id'])}`)
608+
.join(' OR ') +
609+
` NOT creator:"${user?.['https://publiq.be/uitidv1id'] ?? user?.sub}"`,
595610
},
596611
{
597-
enabled: suggestedOrganizerIds.data?.member?.length > 0,
612+
enabled: tab === 'organizers' && recentUsedOrganizers.length > 0,
598613
},
599614
);
600615

0 commit comments

Comments
 (0)