Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

III-6364-Request ownership from the organizer detail page #955

Merged
merged 63 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
4467200
Add ownerId search param
vhande Nov 19, 2024
dddff0e
Add useRequestOwnershipMutation
vhande Nov 19, 2024
c6c5399
Add message OWNERSHIP_REQUEST_DIALOG_OPENED
vhande Nov 19, 2024
5ca7903
Add translations
vhande Nov 19, 2024
26c4604
Add path /organizers
vhande Nov 19, 2024
81e0fa3
Add redirects
vhande Nov 19, 2024
7012e3c
Progress on organizers page
vhande Nov 19, 2024
0becf9b
Fix authenticated query
vhande Nov 19, 2024
7a4068b
Progress on fixing the search params
vhande Nov 19, 2024
83dd82f
Fix lint
vhande Nov 19, 2024
ca93f75
Add useGetOrganizerPermissions
vhande Nov 20, 2024
fb3ebd3
Add utils formatOrganizerDetail
vhande Nov 20, 2024
68a4e6f
Add description
vhande Nov 20, 2024
b11c542
Add mainImage
vhande Nov 20, 2024
c15c833
Add organizer table
vhande Nov 20, 2024
5205479
Export get address
vhande Nov 20, 2024
0ac16f9
Progress on the preview page
vhande Nov 20, 2024
4a24102
Add nl translations
vhande Nov 20, 2024
2a05c2c
Fix lint
vhande Nov 20, 2024
dae6fa2
Fix duplicate mutation
vhande Nov 21, 2024
dae5cc2
Delete unused window message
vhande Nov 21, 2024
99a8fc6
Add nl translations
vhande Nov 21, 2024
38a25c6
Export label pattern
vhande Nov 21, 2024
df8aefa
Add organizer labels
vhande Nov 21, 2024
b75ec72
Add labels to the table
vhande Nov 21, 2024
b691b76
Update preview page
vhande Nov 21, 2024
ff474b9
Add translations
vhande Nov 21, 2024
d995f07
Add translations
vhande Nov 21, 2024
8242bc8
Update success alert
vhande Nov 21, 2024
46cfd8c
Fix render bug
vhande Nov 21, 2024
fa7eab4
Delete iframe
vhande Nov 21, 2024
21012e9
Change button variant
vhande Nov 21, 2024
0eb032b
Use try catch
vhande Nov 21, 2024
4384a1c
Delete unused imports
vhande Nov 21, 2024
a1023fd
Delete ff angular
vhande Nov 21, 2024
4a7cd94
Add dehydratedState
vhande Nov 21, 2024
a5063e1
Fix external link
vhande Nov 21, 2024
d395343
Delete import
vhande Nov 21, 2024
a5755db
Simplify try/catch block
vhande Nov 22, 2024
a8a61f0
Refactor disabled mutations
vhande Nov 22, 2024
abd8c8b
Use Link instead of Button
vhande Nov 22, 2024
564f7ef
Fix styling
vhande Nov 22, 2024
cc2a99e
Add link prop types
vhande Nov 22, 2024
e75554a
Fix unique key
vhande Nov 22, 2024
7a657e8
Create handleErrorObject.ts
vhande Nov 22, 2024
bff49bc
Implement handleErrorObject
vhande Nov 22, 2024
5dba2ce
Fix lint
vhande Nov 22, 2024
d092d8b
Improve types
vhande Nov 22, 2024
f4069bc
Update OrganizerTable
vhande Nov 22, 2024
fb1e719
Remove useMemo
vhande Nov 22, 2024
18df1fd
Restructure the HTML
vhande Nov 22, 2024
60aea74
Delete async
vhande Nov 22, 2024
0182bc6
Delete replaceHTMLTags
vhande Nov 22, 2024
310f0a8
Add sanitize-html
vhande Nov 22, 2024
2ae6aa1
Implement sanitizeHtml
vhande Nov 22, 2024
1afc5e2
Merge branch 'main' into feature/III-6364
vhande Nov 22, 2024
2e3bdd0
Add lockfile after install
simon-debruijn Nov 22, 2024
ea99c39
Fix ts issues
simon-debruijn Nov 22, 2024
a0d7e68
Use rem
vhande Nov 22, 2024
161b049
Merge branch 'feature/III-6364' of https://github.com/cultuurnet/udb3…
vhande Nov 22, 2024
fc17f31
Fix format
vhande Nov 22, 2024
a75f484
Remove @ts-expect-error
vhande Nov 22, 2024
0ed7619
Merge branch 'main' into feature/III-6364
vhande Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"react-query": "^3.2.0",
"react-router": "^5.2.0",
"react-table": "^7.6.3",
"sanitize-html": "^2.13.1",
"sass": "^1.27.0",
"sass-loader": "^10.0.4",
"socket.io-client": "2.3.0",
Expand Down
19 changes: 12 additions & 7 deletions src/hooks/api/authenticated-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ const isDuplicateMutation = (

// Temporary disable caching on price-info
// https://jira.uitdatabank.be/browse/III-5620
if (mutationKey === 'offers-add-price-info') {
return false;
}

if (mutationKey === 'offers-change-calendar') {
return false;
}
const disabledMutations = [
'offers-add-price-info',
'offers-change-calendar',
'places-add',
'request-ownership',
];

if (mutationKey === 'places-add') {
if (disabledMutations.includes(mutationKey)) {
return false;
}
vhande marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -189,6 +189,11 @@ const isDuplicateMutation = (

const latestMutation = mutations.slice(-2)[0];

// If the latest mutation was unsuccessful, we don't want to trigger a false positive.
if (latestMutation.state.error) {
return false;
}

return (
mutations.length > 1 && isEqual(latestMutation.options.variables, variables)
);
Expand Down
33 changes: 33 additions & 0 deletions src/hooks/api/organizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { UseMutationOptions, UseQueryOptions } from 'react-query';
import type {
AuthenticatedQueryOptions,
PaginationOptions,
ServerSideQueryOptions,
SortOptions,
} from '@/hooks/api/authenticated-query';
import {
Expand All @@ -12,6 +13,7 @@ import {
import type { Organizer } from '@/types/Organizer';
import { createSortingArgument } from '@/utils/createSortingArgument';
import { fetchFromApi, isErrorObject } from '@/utils/fetchFromApi';
import { handleErrorObject } from '@/utils/handleErrorObject';

import type { Headers } from './types/Headers';
import type { User } from './user';
Expand Down Expand Up @@ -165,6 +167,36 @@ const getOrganizersByCreator = async ({
return await res.json();
};

type UseGetOrganizerPermissionsArguments = ServerSideQueryOptions & {
organizerId: string;
};

const getOrganizerPermissions = async ({ headers, organizerId }) => {
const res = await fetchFromApi({
path: `/organizers/${organizerId}/permissions`,
options: { headers },
});

return handleErrorObject(res);
};

export type GetOrganizerPermissionsResponse = {
permissions: string[];
};
const useGetOrganizerPermissions = (
{ req, queryClient, organizerId }: UseGetOrganizerPermissionsArguments,
configuration: UseQueryOptions = {},
) =>
useAuthenticatedQuery<GetOrganizerPermissionsResponse>({
req,
queryClient,
queryKey: ['ownership-permissions'],
queryFn: getOrganizerPermissions,
queryArguments: { organizerId },
refetchOnWindowFocus: false,
...configuration,
});

const deleteOrganizerById = async ({ headers, id }) =>
fetchFromApi({
path: `/organizers/${id}`,
Expand Down Expand Up @@ -357,6 +389,7 @@ export {
useDeleteOrganizerByIdMutation,
useDeleteOrganizerEducationalDescriptionMutation,
useGetOrganizerByIdQuery,
useGetOrganizerPermissions,
useGetOrganizersByCreatorQuery,
useGetOrganizersByQueryQuery,
useGetOrganizersByWebsiteQuery,
Expand Down
30 changes: 27 additions & 3 deletions src/hooks/api/ownerships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export const RequestState = {

type RequestState = Values<typeof RequestState>;

const getOwnershipRequests = async ({ headers, organizerId }) => {
const getOwnershipRequests = async ({ headers, organizerId, ownerId }) => {
const res = await fetchFromApi({
path: '/ownerships/',
searchParams: {
itemId: organizerId,
...(ownerId && { ownerId }),
},
options: {
headers,
Expand All @@ -49,22 +50,44 @@ const getOwnershipRequests = async ({ headers, organizerId }) => {

type UseGetOwnershipRequestsArguments = ServerSideQueryOptions & {
organizerId: string;
ownerId?: string;
};

const useGetOwnershipRequestsQuery = (
{ req, queryClient, organizerId }: UseGetOwnershipRequestsArguments,
{ req, queryClient, organizerId, ownerId }: UseGetOwnershipRequestsArguments,
configuration: UseQueryOptions = {},
) =>
useAuthenticatedQuery<OwnershipRequest[]>({
req,
queryClient,
queryKey: ['ownership-requests'],
queryFn: getOwnershipRequests,
queryArguments: { organizerId },
queryArguments: { organizerId, ...(ownerId && { ownerId }) },
refetchOnWindowFocus: false,
...configuration,
});

const requestOwnership = async ({ headers, itemId, ownerId }) =>
fetchFromApi({
path: '/ownerships',
options: {
method: 'POST',
headers,
body: JSON.stringify({
itemId,
itemType: 'organizer',
ownerId,
}),
},
});
Anahkiasen marked this conversation as resolved.
Show resolved Hide resolved

const useRequestOwnershipMutation = (configuration = {}) =>
useAuthenticatedMutation({
mutationFn: requestOwnership,
mutationKey: 'request-ownership',
...configuration,
});

const approveOwnershipRequest = async ({ headers, ownershipId }) =>
fetchFromApi({
path: `/ownerships/${ownershipId}/approve`,
Expand Down Expand Up @@ -151,4 +174,5 @@ export {
useGetOwnershipCreatorQuery,
useGetOwnershipRequestsQuery,
useRejectOwnershipRequestMutation,
useRequestOwnershipMutation,
};
2 changes: 1 addition & 1 deletion src/hooks/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const getUser = async (cookies: Cookies) => {
const useGetUserQuery = () => {
const { cookies } = useCookiesWithOptions(['idToken']);

return useAuthenticatedQuery({
return useAuthenticatedQuery<User>({
queryKey: ['user'],
queryFn: () => getUser(cookies),
});
Expand Down
25 changes: 12 additions & 13 deletions src/hooks/useLegacyPath.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import getConfig from 'next/config';
import { useRouter } from 'next/router';
import { useMemo } from 'react';
import { useEffect, useMemo } from 'react';

import { useCookiesWithOptions } from './useCookiesWithOptions';
import { useSearchParams } from './useSearchParams';

const useLegacyPath = () => {
const { cookies } = useCookiesWithOptions(['token', 'udb-language']);
const router = useRouter();
const searchParams = useSearchParams();
const { publicRuntimeConfig } = getConfig();
const prefixWhenNotEmpty = (value, prefix) =>
value ? `${prefix}${value}` : value;
Expand All @@ -15,24 +17,21 @@ const useLegacyPath = () => {
const lang = cookies['udb-language'];

const legacyPath = useMemo(() => {
const path = new URL(`http://localhost${router.asPath}`).pathname;
const { params = [], ...queryWithoutParams } = router.query;
const queryString = prefixWhenNotEmpty(
new URLSearchParams({
...queryWithoutParams,
jwt,
lang,
}),
'?',
);
const path = new URL(router.asPath, publicRuntimeConfig.legacyAppUrl)
.pathname;
searchParams.set('jwt', jwt);
searchParams.set('lang', lang);

return `${publicRuntimeConfig.legacyAppUrl}${path}${queryString}`;
return `${publicRuntimeConfig.legacyAppUrl}${path}${prefixWhenNotEmpty(
searchParams.toString(),
'?',
)}`;
}, [
router.asPath,
router.query,
jwt,
lang,
publicRuntimeConfig.legacyAppUrl,
searchParams,
]);

return legacyPath;
Expand Down
25 changes: 25 additions & 0 deletions src/hooks/useSearchParams.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useRouter } from 'next/router';
import { useMemo } from 'react';

export const useSearchParams = () => {
const { query, pathname } = useRouter();

return useMemo(() => {
const params = new URLSearchParams();

const filtered = Object.entries(query).filter(([key]) => {
return !pathname.includes(`[${key}]`);
});

filtered.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach((v) => params.append(key, v));
return;
}

params.set(key, value);
});

return params;
}, [query, pathname]);
};
vhande marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,25 @@
}
},
"organizers": {
"detail": {
"name": "Name",
"description": "Beschreibung",
"educationalDescription": "Beschreibung Cultuurkuur",
"address": "Adresse",
"no_address": "Keine Adresse",
"contact": "Kontakt",
"no_contact": "Keine Kontaktinformationen",
"labels": "Labels",
"images": "Bilder",
"no_images": "Keine Bilder",
"mainImage": "Hauptbild",
"actions": {
"edit": "Bearbeiten",
"manage": "Anforderungsmanagement",
"request": "Verwaltung anfordern",
"back": "Zurück zum Dashboard"
}
},
"create": {
"title": "Organisation hinzufügen",
"step1": {
Expand Down Expand Up @@ -1053,6 +1072,16 @@
"body": "Sind Sie sicher, dass Sie {{ownerEmail}} als Verwalter entfernen möchten?",
"cancel": "Abbrechen",
"confirm": "Verwalter entfernen"
},
"request": {
"confirm_modal": {
"title": "Verwaltungsanfrage für {{organizerName}}",
"body": "Sind Sie im Vorstand von {{organizerName}} und möchten Sie die Organisationsseite und Veranstaltungen verwalten? Starten Sie hier Ihre Anfrage, um Administrator zu werden. Sobald ein aktueller Administrator Ihre Anfrage genehmigt, erhalten Sie Zugriff und eine Bestätigung per E-Mail.",
"cancel": "Abbrechen",
"confirm": "Verwaltungsanfrage"
},
"pending": "Ihre Anfrage zur Verwaltung von {{organizerName}} wird bearbeitet.<br/>Sobald ein aktueller Administrator Ihre Anfrage genehmigt hat, erhalten Sie Zugriff und eine Bestätigung per E-Mail.",
"success": "Ihre Anfrage zur Verwaltung der Seite von {{organizerName}} und ihrer Veranstaltungen wurde erfolgreich gesendet!<br/>Sobald ein aktueller Administrator Ihre Anfrage genehmigt, erhalten Sie Zugriff und eine Bestätigung per E-Mail."
}
}
},
Expand Down
29 changes: 29 additions & 0 deletions src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,25 @@
}
},
"organizers": {
"detail": {
"name": "Nom",
"description": "Description",
"educationalDescription": "Description Cultuurkuur",
"address": "Adresse",
"no_address": "Aucune adresse",
"contact": "Contact",
"no_contact": "Aucune information de contact",
"labels": "Labels",
"images": "Images",
"no_images": "Aucune image",
"mainImage": "Image principale",
"actions": {
"edit": "Modifier",
"manage": "Gestion des demandes",
"request": "Demander gestion",
"back": "Retourner au tableau de bord"
}
},
"create": {
"title": "Ajouter une organisation",
"step1": {
Expand Down Expand Up @@ -1053,6 +1072,16 @@
"body": "Êtes-vous sûr de vouloir supprimer {{ownerEmail}} en tant que gestionnaire ?",
"cancel": "Annuler",
"confirm": "Supprimer le gestionnaire"
},
"request": {
"confirm_modal": {
"title": "Demande de gestion pour {{organizerName}}",
"body": "Êtes-vous impliqué dans la gestion de {{organizerName}} et souhaitez-vous gérer la page de l'organisation et de ses événements ? Commencez ici votre demande pour devenir administrateur. Une fois qu'un administrateur actuel approuve votre demande, vous recevrez l'accès et une confirmation par e-mail.",
"cancel": "Annuler",
"confirm": "Demander la gestion"
},
"pending": "Votre demande pour gérer {{organizerName}} est en cours de traitement.<br/>Dès qu'un administrateur actuel aura approuvé votre demande, vous recevrez l'accès et une confirmation par e-mail.",
"success": "Votre demande pour gérer la page de {{organizerName}} et ses événements a été envoyée avec succès !<br/>Dès qu'un administrateur actuel approuve votre demande, vous recevrez l'accès et une confirmation par e-mail."
}
}
},
Expand Down
30 changes: 30 additions & 0 deletions src/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,25 @@
}
},
"organizers": {
"detail": {
"name": "Naam",
"description": "Bescrijving",
"educationalDescription": "Beschrijving Cultuurkuur",
"address": "Adres",
"no_address": "Geen address",
"contact": "Contact",
"no_contact": "Geen contactinformatie",
"labels": "Labels",
"images": "Afbeeldingen",
"no_images": "Geen afbeeldingen",
"mainImage": "Hoofdafbeelding",
"actions": {
"edit": "Bewerken",
"manage": "Beheerders aanpassen",
"request": "Beheer aanvragen",
"back": "Terug naar dashboard"
}
},
"create": {
"title": "Organisatie toevoegen",
"step1": {
Expand Down Expand Up @@ -1053,6 +1072,17 @@
"body": "Ben je zeker dat je {{ownerEmail}} wilt verwijderen als beheerder?",
"cancel": "Annuleren",
"confirm": "Beheerder verwijderen"
},
"request": {
"confirm_modal": {
"title": "Beheer aanvragen voor {{organizerName}}",
"body": "Ben je betrokken bij het bestuur van {{organizerName}} en wil je de organisatiepagina en evenementen ervan beheren? Start hier je aanvraag om beheerder te worden. Zodra een huidige beheerder je aanvraag goedkeurt, krijg je toegang en ontvang je een bevestiging via e-mail.",
"cancel": "Annuleren",
"confirm": "Beheer aanvragen",
"error": "Er is iets misgelopen"
},
"pending": "Je aanvraag tot het beheer van {{organizerName}} is in behandeling.<br/>Zodra een huidige beheerder je aanvraag heeft goedgekeurd, krijg je toegang en ontvang je een bevestiging via e-mail.",
"success": "Je aanvraag om beheerder te worden van {{organizerName}} is succesvol verzonden!<br/>Zodra een huidige beheerder je aanvraag heeft goedgekeurd, krijg je toegang en ontvang je een bevestiging via e-mail."
}
}
},
Expand Down
Loading
Loading