Aanbod: categorieën beheren in een dialoog en categorie kiezen in het aanbodformulier
Knop 'Categorieën beheren' op de aanbodlijst opent een dialoog om categorieën toe te voegen, te hernoemen en te verwijderen, met Nederlandse meldingen voor een dubbele naam en een categorie die nog in gebruik is. Het formulier krijgt een keuzelijst met 'Geen categorie', de lijst toont de categorie als badge en de querykey ['offerings','list'] vervangt de oude admin-key zodat een hernoeming direct zichtbaar is. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,10 @@ export interface OfferingDto {
|
||||
ctaLabel: string;
|
||||
featured: boolean;
|
||||
displayOrder: number;
|
||||
/** Id of the category, or null/absent when the offering has none. */
|
||||
categoryId?: string | null;
|
||||
/** Name of the category (renames show up here automatically). */
|
||||
category?: string | null;
|
||||
}
|
||||
|
||||
export interface CreateOfferingRequest {
|
||||
@@ -21,8 +25,17 @@ export interface CreateOfferingRequest {
|
||||
featured: boolean;
|
||||
/** Omit to auto-generate from title; set to explicitly override. */
|
||||
slug?: string;
|
||||
/** Category id; null clears the category. */
|
||||
categoryId?: string | null;
|
||||
}
|
||||
|
||||
export type UpdateOfferingRequest = CreateOfferingRequest;
|
||||
|
||||
export interface OfferingCategoryDto {
|
||||
id: string;
|
||||
name: string;
|
||||
sortOrder: number;
|
||||
offeringCount: number;
|
||||
}
|
||||
|
||||
export type MoveDirection = 'up' | 'down';
|
||||
|
||||
@@ -9,7 +9,7 @@ export function useCreateOffering(
|
||||
return useMutation<OfferingDto, Error, CreateOfferingRequest>({
|
||||
mutationFn: (data) => api.post<OfferingDto>('/api/v1/offerings', data),
|
||||
onSuccess: (data, variables, ...rest) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'admin'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] });
|
||||
options?.onSuccess?.(data, variables, ...rest);
|
||||
},
|
||||
onError: options?.onError,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from '@/lib/api-client';
|
||||
import { OFFERING_CATEGORIES_KEY } from './useOfferingCategories';
|
||||
import type { OfferingCategoryDto } from './types';
|
||||
|
||||
export function useCreateOfferingCategory() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<OfferingCategoryDto, Error, string>({
|
||||
mutationFn: (name) =>
|
||||
api.post<OfferingCategoryDto>('/api/v1/offerings/categories', { name }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: OFFERING_CATEGORIES_KEY });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -8,7 +8,7 @@ export function useDeleteOffering(
|
||||
return useMutation<void, Error, string>({
|
||||
mutationFn: (id) => api.delete<void>(`/api/v1/offerings/${id}`),
|
||||
onSuccess: (data, variables, ...rest) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'admin'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] });
|
||||
options?.onSuccess?.(data, variables, ...rest);
|
||||
},
|
||||
onError: options?.onError,
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from '@/lib/api-client';
|
||||
import { OFFERING_CATEGORIES_KEY } from './useOfferingCategories';
|
||||
|
||||
export function useDeleteOfferingCategory() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<void, Error, string>({
|
||||
mutationFn: (id) => api.delete<void>(`/api/v1/offerings/categories/${id}`),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: OFFERING_CATEGORIES_KEY });
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient, type UseMutationOptions } from '@tanstack/
|
||||
import { api } from '@/lib/api-client';
|
||||
import type { MoveDirection, OfferingDto } from './types';
|
||||
|
||||
const OFFERINGS_KEY = ['offerings', 'admin'];
|
||||
const OFFERINGS_KEY = ['offerings', 'list'];
|
||||
|
||||
/**
|
||||
* Moves one offering a step up or down. The API has no move endpoint (the collection is reordered
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '@/lib/api-client';
|
||||
import type { OfferingCategoryDto } from './types';
|
||||
|
||||
export const OFFERING_CATEGORIES_KEY = ['offerings', 'categories'];
|
||||
|
||||
export function useOfferingCategories() {
|
||||
return useQuery<OfferingCategoryDto[], Error>({
|
||||
queryKey: OFFERING_CATEGORIES_KEY,
|
||||
queryFn: () => api.get<OfferingCategoryDto[]>('/api/v1/offerings/categories'),
|
||||
});
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import type { OfferingDto } from './types';
|
||||
|
||||
export function useOfferings() {
|
||||
return useQuery<OfferingDto[], Error>({
|
||||
queryKey: ['offerings', 'admin'],
|
||||
queryKey: ['offerings', 'list'],
|
||||
queryFn: () => api.get<OfferingDto[]>('/api/v1/offerings'),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { api } from '@/lib/api-client';
|
||||
import { OFFERING_CATEGORIES_KEY } from './useOfferingCategories';
|
||||
import type { OfferingCategoryDto } from './types';
|
||||
|
||||
type RenameVariables = { id: string; name: string };
|
||||
|
||||
export function useRenameOfferingCategory() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<OfferingCategoryDto, Error, RenameVariables>({
|
||||
mutationFn: ({ id, name }) =>
|
||||
api.put<OfferingCategoryDto>(`/api/v1/offerings/categories/${id}`, { name }),
|
||||
onSuccess: () => {
|
||||
// The category name is part of every offering that uses it, so refresh both lists.
|
||||
queryClient.invalidateQueries({ queryKey: OFFERING_CATEGORIES_KEY });
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -8,7 +8,7 @@ export function useReorderOfferings(
|
||||
return useMutation<void, Error, string[]>({
|
||||
mutationFn: (orderedIds) => api.put<void>('/api/v1/offerings/order', { orderedIds }),
|
||||
onSuccess: (data, variables, ...rest) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'admin'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] });
|
||||
options?.onSuccess?.(data, variables, ...rest);
|
||||
},
|
||||
onError: options?.onError,
|
||||
|
||||
@@ -11,7 +11,7 @@ export function useUpdateOffering(
|
||||
return useMutation<OfferingDto, Error, UpdateVariables>({
|
||||
mutationFn: ({ id, ...body }) => api.put<OfferingDto>(`/api/v1/offerings/${id}`, body),
|
||||
onSuccess: (data, variables, ...rest) => {
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'admin'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['offerings', 'list'] });
|
||||
options?.onSuccess?.(data, variables, ...rest);
|
||||
},
|
||||
onError: options?.onError,
|
||||
|
||||
Reference in New Issue
Block a user