Adds the Offerings module and retargets the CI/CD pipeline to Api.SlpSoftware
Continuous Integration / config (pull_request) Successful in 12s
Continuous Integration / changes (pull_request) Successful in 22s
Continuous Integration / backend-build (pull_request) Successful in 5m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 5m46s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m54s
Continuous Integration / backend-test (pull_request) Successful in 7m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m14s
Continuous Integration / frontend-test (pull_request) Successful in 4m59s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 7m34s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / config (pull_request) Successful in 12s
Continuous Integration / changes (pull_request) Successful in 22s
Continuous Integration / backend-build (pull_request) Successful in 5m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 5m46s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m54s
Continuous Integration / backend-test (pull_request) Successful in 7m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m14s
Continuous Integration / frontend-test (pull_request) Successful in 4m59s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 7m34s
Continuous Integration / deploy-test (pull_request) Skipped
Implements Unit 2 "Offerings" (backend module, admin CRUD UI with drag-and-drop reordering, public GET /api/v1/offerings endpoint) and executes the feature's D-15 CI/CD cutover, switching the deploy pipeline's build/publish target from SlpModularCms.Api to SlpModularCms.Api.SlpSoftware. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FWyStNL2ZsjrS7FLd7xvvN
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import type { OfferingAdminDto } from '../services/types';
|
||||
|
||||
interface DeleteOfferingDialogProps {
|
||||
offering: OfferingAdminDto | null;
|
||||
isDeleting: boolean;
|
||||
onConfirm: () => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function DeleteOfferingDialog({ offering, isDeleting, onConfirm, onCancel }: DeleteOfferingDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Dialog open={offering !== null} onOpenChange={(open) => { if (!open) onCancel(); }}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('offerings.deleteDialog.title')}</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<p className="text-sm text-muted-foreground" data-testid="delete-offering-message">
|
||||
{t('offerings.deleteDialog.message', { title: offering?.title ?? '' })}
|
||||
</p>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" onClick={onCancel} data-testid="delete-offering-cancel">
|
||||
{t('offerings.deleteDialog.cancelButton')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={onConfirm}
|
||||
disabled={isDeleting}
|
||||
data-testid="delete-offering-confirm"
|
||||
>
|
||||
{isDeleting ? '…' : t('offerings.deleteDialog.confirmButton')}
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import { useForm, useWatch } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Plus, Trash2 } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { FieldError } from '@/components/ui/FieldError';
|
||||
import { offeringFormSchema, type OfferingFormData } from '../schemas/offering';
|
||||
import type { OfferingAdminDto } from '../services/types';
|
||||
|
||||
interface OfferingFormProps {
|
||||
initialValues?: OfferingAdminDto;
|
||||
onSubmit: (values: OfferingFormData) => void;
|
||||
isSubmitting: boolean;
|
||||
}
|
||||
|
||||
export function OfferingForm({ initialValues, onSubmit, isSubmitting }: OfferingFormProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const {
|
||||
register,
|
||||
control,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm<OfferingFormData>({
|
||||
resolver: zodResolver(offeringFormSchema),
|
||||
mode: 'onTouched',
|
||||
defaultValues: initialValues ?? {
|
||||
title: '',
|
||||
description: '',
|
||||
price: '',
|
||||
priceNote: '',
|
||||
features: [''],
|
||||
ctaLabel: '',
|
||||
featured: false,
|
||||
},
|
||||
});
|
||||
|
||||
// useFieldArray requires object-shaped array items — features is a plain string[],
|
||||
// so add/remove are handled directly via setValue instead.
|
||||
const features = useWatch({ control, name: 'features' });
|
||||
|
||||
function addFeature() {
|
||||
setValue('features', [...features, ''], { shouldValidate: true });
|
||||
}
|
||||
|
||||
function removeFeature(index: number) {
|
||||
setValue('features', features.filter((_, i) => i !== index), { shouldValidate: true });
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)} noValidate className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="offering-title">{t('offerings.form.titleLabel')}</Label>
|
||||
<Input id="offering-title" data-testid="offering-title" aria-invalid={errors.title !== undefined} {...register('title')} />
|
||||
{errors.title && <FieldError message={errors.title.message} testId="offering-title-error" />}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="offering-description">{t('offerings.form.descriptionLabel')}</Label>
|
||||
<textarea
|
||||
id="offering-description"
|
||||
data-testid="offering-description"
|
||||
aria-invalid={errors.description !== undefined}
|
||||
className="flex min-h-24 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||
{...register('description')}
|
||||
/>
|
||||
{errors.description && <FieldError message={errors.description.message} testId="offering-description-error" />}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="offering-price">{t('offerings.form.priceLabel')}</Label>
|
||||
<Input id="offering-price" data-testid="offering-price" aria-invalid={errors.price !== undefined} {...register('price')} />
|
||||
{errors.price && <FieldError message={errors.price.message} testId="offering-price-error" />}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="offering-price-note">{t('offerings.form.priceNoteLabel')}</Label>
|
||||
<Input
|
||||
id="offering-price-note"
|
||||
data-testid="offering-price-note"
|
||||
aria-invalid={errors.priceNote !== undefined}
|
||||
{...register('priceNote')}
|
||||
/>
|
||||
{errors.priceNote && <FieldError message={errors.priceNote.message} testId="offering-price-note-error" />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>{t('offerings.form.featuresLabel')}</Label>
|
||||
{features.map((_, index) => (
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
<Input
|
||||
data-testid={`offering-feature-${index}`}
|
||||
aria-invalid={errors.features?.[index] !== undefined}
|
||||
{...register(`features.${index}` as const)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-testid={`offering-feature-${index}-remove`}
|
||||
aria-label={t('offerings.form.removeFeatureButton')}
|
||||
disabled={features.length <= 1}
|
||||
onClick={() => removeFeature(index)}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
{errors.features?.message && <FieldError message={errors.features.message} testId="offering-features-error" />}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
data-testid="offering-add-feature"
|
||||
disabled={features.length >= 10}
|
||||
onClick={addFeature}
|
||||
>
|
||||
<Plus className="size-4" />
|
||||
{t('offerings.form.addFeatureButton')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="offering-cta-label">{t('offerings.form.ctaLabelLabel')}</Label>
|
||||
<Input
|
||||
id="offering-cta-label"
|
||||
data-testid="offering-cta-label"
|
||||
aria-invalid={errors.ctaLabel !== undefined}
|
||||
{...register('ctaLabel')}
|
||||
/>
|
||||
{errors.ctaLabel && <FieldError message={errors.ctaLabel.message} testId="offering-cta-label-error" />}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
id="offering-featured"
|
||||
type="checkbox"
|
||||
data-testid="offering-featured"
|
||||
className="size-4 rounded border-input"
|
||||
{...register('featured')}
|
||||
/>
|
||||
<Label htmlFor="offering-featured">{t('offerings.form.featuredLabel')}</Label>
|
||||
</div>
|
||||
|
||||
<Button type="submit" disabled={isSubmitting} data-testid="offering-form-submit">
|
||||
{isSubmitting ? '…' : t('offerings.form.submitButton')}
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { useSortable } from '@dnd-kit/sortable';
|
||||
import { CSS } from '@dnd-kit/utilities';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { GripVertical, Star, ChevronUp, ChevronDown, Pencil, Trash2 } from 'lucide-react';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { TableCell, TableRow } from '@/components/ui/table';
|
||||
import { useUpdateOffering } from '../services/useUpdateOffering';
|
||||
import { useMoveOffering } from '../services/useMoveOffering';
|
||||
import type { OfferingAdminDto } from '../services/types';
|
||||
|
||||
interface OfferingRowProps {
|
||||
offering: OfferingAdminDto;
|
||||
isFirst: boolean;
|
||||
isLast: boolean;
|
||||
onDeleteRequested: () => void;
|
||||
}
|
||||
|
||||
export function OfferingRow({ offering, isFirst, isLast, onDeleteRequested }: OfferingRowProps) {
|
||||
const { t } = useTranslation();
|
||||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: offering.id });
|
||||
const updateOffering = useUpdateOffering();
|
||||
const moveUp = useMoveOffering('up');
|
||||
const moveDown = useMoveOffering('down');
|
||||
|
||||
// The moving visual is rendered by <DragOverlay> instead (see OfferingsList) — a portal
|
||||
// outside the document flow, so it can't grow the page's scrollable area the way
|
||||
// transforming this row in place would. This row just hides itself while dragging.
|
||||
const style = {
|
||||
transform: CSS.Transform.toString(transform),
|
||||
transition,
|
||||
opacity: isDragging ? 0 : 1,
|
||||
};
|
||||
|
||||
return (
|
||||
<TableRow ref={setNodeRef} style={style} data-testid={`offering-row-${offering.id}`}>
|
||||
<TableCell>
|
||||
<button
|
||||
type="button"
|
||||
className="cursor-grab text-muted-foreground touch-none"
|
||||
aria-label={t('offerings.actions.drag')}
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
>
|
||||
<GripVertical className="size-4" />
|
||||
</button>
|
||||
</TableCell>
|
||||
<TableCell>{offering.title}</TableCell>
|
||||
<TableCell>{offering.price}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-testid={`offering-row-${offering.id}-featured-toggle`}
|
||||
aria-label={offering.featured ? t('offerings.actions.unmarkFeatured') : t('offerings.actions.markFeatured')}
|
||||
onClick={() =>
|
||||
updateOffering.mutate({
|
||||
id: offering.id,
|
||||
title: offering.title,
|
||||
description: offering.description,
|
||||
price: offering.price,
|
||||
priceNote: offering.priceNote,
|
||||
features: offering.features,
|
||||
ctaLabel: offering.ctaLabel,
|
||||
featured: !offering.featured,
|
||||
})
|
||||
}
|
||||
>
|
||||
<Star className={`size-4 ${offering.featured ? 'fill-yellow-400 text-yellow-400' : ''}`} />
|
||||
</Button>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-testid={`offering-row-${offering.id}-move-up-button`}
|
||||
aria-label={t('offerings.actions.moveUp')}
|
||||
disabled={isFirst}
|
||||
onClick={() => moveUp.mutate(offering.id)}
|
||||
>
|
||||
<ChevronUp className="size-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-testid={`offering-row-${offering.id}-move-down-button`}
|
||||
aria-label={t('offerings.actions.moveDown')}
|
||||
disabled={isLast}
|
||||
onClick={() => moveDown.mutate(offering.id)}
|
||||
>
|
||||
<ChevronDown className="size-4" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon" asChild data-testid={`offering-row-${offering.id}-edit-link`}>
|
||||
<Link to="/offerings/$id/edit" params={{ id: offering.id }} aria-label={t('offerings.actions.edit')}>
|
||||
<Pencil className="size-4" />
|
||||
</Link>
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-testid={`offering-row-${offering.id}-delete-button`}
|
||||
aria-label={t('offerings.actions.delete')}
|
||||
onClick={onDeleteRequested}
|
||||
>
|
||||
<Trash2 className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { DndContext, DragOverlay, closestCenter } from '@dnd-kit/core';
|
||||
import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { GripVertical } from 'lucide-react';
|
||||
import { Table, TableBody, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { OfferingRow } from './OfferingRow';
|
||||
import { useOfferingsDnd } from '../hooks/useOfferingsDnd';
|
||||
import type { OfferingAdminDto } from '../services/types';
|
||||
|
||||
interface OfferingsListProps {
|
||||
offerings: OfferingAdminDto[];
|
||||
onDeleteRequested: (offering: OfferingAdminDto) => void;
|
||||
}
|
||||
|
||||
export function OfferingsList({ offerings, onDeleteRequested }: OfferingsListProps) {
|
||||
const { t } = useTranslation();
|
||||
const { items, sensors, activeItem, handleDragStart, handleDragEnd } = useOfferingsDnd(offerings);
|
||||
|
||||
return (
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragStart={handleDragStart}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead />
|
||||
<TableHead>{t('offerings.table.title')}</TableHead>
|
||||
<TableHead>{t('offerings.table.price')}</TableHead>
|
||||
<TableHead>{t('offerings.table.featured')}</TableHead>
|
||||
<TableHead>{t('offerings.table.actions')}</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<SortableContext items={items.map((o) => o.id)} strategy={verticalListSortingStrategy}>
|
||||
{items.map((offering, index) => (
|
||||
<OfferingRow
|
||||
key={offering.id}
|
||||
offering={offering}
|
||||
isFirst={index === 0}
|
||||
isLast={index === items.length - 1}
|
||||
onDeleteRequested={() => onDeleteRequested(offering)}
|
||||
/>
|
||||
))}
|
||||
</SortableContext>
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
{/* Rendered in a portal outside document flow, so the dragged item's position
|
||||
never grows the page's scrollable area the way transforming a table row in
|
||||
place would (a real browser behavior with in-place transforms, not a bug in
|
||||
dnd-kit itself). */}
|
||||
<DragOverlay>
|
||||
{activeItem && (
|
||||
<div className="flex items-center gap-3 rounded-md border border-border bg-card px-4 py-3 shadow-lg">
|
||||
<GripVertical className="size-4 text-muted-foreground" />
|
||||
<span className="font-medium">{activeItem.title}</span>
|
||||
<span className="text-muted-foreground">{activeItem.price}</span>
|
||||
</div>
|
||||
)}
|
||||
</DragOverlay>
|
||||
</DndContext>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user