Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions backend/src/demo/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ async fn bike_flea_market(demo: &mut Demo<'_>, people: &People) -> anyhow::Resul
categories: &[Cat::Bikes],
cover: "cover_bikes",
features: json!({
"eventType": "bikeExchange",
"directSale": true,
"discounts": false,
"priceOffers": false,
Expand Down Expand Up @@ -813,6 +814,7 @@ async fn kids_bazaar(demo: &mut Demo<'_>, people: &People) -> anyhow::Result<()>
categories: &[Cat::Clothing, Cat::Shoes, Cat::Toys, Cat::Books, Cat::Other, Cat::BabyKids, Cat::Bikes, Cat::Sports, Cat::Furniture],
cover: "cover_clothes",
features: json!({
"eventType": "kidsBazaar",
"discounts": true,
"discountStartsAt": millis(now - Duration::minutes(30)),
"maxDiscountPercent": 50,
Expand Down Expand Up @@ -1114,6 +1116,7 @@ async fn ski_bazaar(demo: &mut Demo<'_>, people: &People) -> anyhow::Result<()>
categories: &[Cat::Sports, Cat::Shoes, Cat::Clothing, Cat::Accessories],
cover: "cover_winter",
features: json!({
"eventType": "skiBazaar",
"discounts": false,
"priceOffers": true,
"minimumPrice": true,
Expand Down
49 changes: 49 additions & 0 deletions backend/src/modules/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const SERVICES: [&str; 6] = [
const VISIBILITIES: [&str; 3] = ["public", "logged-in", "approved"];
const LABEL_FORMATS: [&str; 2] = ["standard", "small"];
const LABEL_MARKS: [&str; 2] = ["universal", "none"];
/// Kinds of bazaars of the creation wizard (`EVENT_TYPES` in src/lib/eventTypes.ts); the
/// conditions pick their worked example by it (#303)
const EVENT_TYPES: [&str; 4] = ["kidsBazaar", "clothingBazaar", "skiBazaar", "bikeExchange"];
/// What viewers outside the team see instead of the access code
const HIDDEN_ACCESS_CODE: &str = "••••";

Expand Down Expand Up @@ -774,6 +777,9 @@ struct FeaturesArgs {
registration_ends_at: Option<f64>,
/// Absent (older apps): the stored groups stay
fee_groups: Option<Vec<FeeGroupArgs>>,
/// The kind of bazaar (#303); null clears it, left out the stored one stays
#[serde(default, with = "serde_with::rust::double_option")]
event_type: Option<Option<String>>,
}

/// One fee group as the form sends it (#302)
Expand Down Expand Up @@ -943,6 +949,11 @@ fn sanitize_features(
{
return Err(invalid("labelMark"));
}
if let Some(Some(kind)) = &features.event_type
&& !EVENT_TYPES.contains(&kind.as_str())
{
return Err(invalid("eventType"));
}
let previous_bool = |key: &str| previous.and_then(|p| p.get(key)).and_then(Value::as_bool);
let previous_number = |key: &str| previous.and_then(|p| p.get(key)).and_then(Value::as_f64);
let required_fields: Option<Vec<String>> = match features.required_fields {
Expand Down Expand Up @@ -1140,6 +1151,16 @@ fn sanitize_features(
.unwrap_or(Value::Null),
},
);
put(
"eventType",
match features.event_type {
Some(kind) => json!(kind),
None => previous
.and_then(|p| p.get("eventType"))
.cloned()
.unwrap_or(Value::Null),
},
);
Ok(Value::Object(stored))
}

Expand Down Expand Up @@ -2206,6 +2227,34 @@ mod tests {
assert!(cleared.get("maxFeesPerSeller").is_none());
}

#[test]
fn event_type_is_known_and_stays_unless_cleared() {
let sanitize = |event_type, previous: Option<&Value>| {
sanitize_features(
FeaturesArgs {
event_type,
..FeaturesArgs::default()
},
previous,
&known(),
)
};
let stored = sanitize(Some(Some("bikeExchange".into())), None).unwrap();
assert_eq!(stored["eventType"], "bikeExchange");
// Not sent by an older client: kept
assert_eq!(
sanitize(None, Some(&stored)).unwrap()["eventType"],
"bikeExchange"
);
assert!(
sanitize(Some(None), Some(&stored))
.unwrap()
.get("eventType")
.is_none()
);
assert!(sanitize(Some(Some("flea".into())), None).is_err());
}

#[test]
fn feature_ranges_are_checked() {
let err = |features: FeaturesArgs| {
Expand Down
44 changes: 30 additions & 14 deletions src/components/events/SellerConditions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,43 @@ vi.mock('../../lib/api/react', () => ({
}));

describe('SellerConditions', () => {
it('shows fees, a worked example, the rules and the times', () => {
render(
it('shows fees, a worked example, the times, then duties and options', () => {
const { container } = render(
<SellerConditions
event={{
commission: 10,
features: { intakeFee: 2, maxItemsPerSeller: 25, priceOffers: true },
features: {
intakeFee: 2,
maxItemsPerSeller: 25,
priceOffers: true,
eventType: 'bikeExchange',
},
sellerLogistics: { pickupStart: Date.UTC(2026, 9, 17, 14) },
}}
/>
);
expect(screen.getByText(/10 % Provision vom Verkaufspreis/)).toBeInTheDocument();
expect(screen.getByText(/10 % Provision auf jeden verkauften Artikel/)).toBeInTheDocument();
expect(screen.getByText(/2,00 € Annahmegebühr pro angenommenem Artikel/)).toBeInTheDocument();
expect(screen.getByText('Rechenbeispiel')).toBeInTheDocument();
expect(screen.getByText('Annahmegebühr 10 × 2,00 €')).toBeInTheDocument();
expect(screen.getByText('−20,00 €')).toBeInTheDocument();
expect(screen.getByText('Du bekommst')).toBeInTheDocument();
expect(screen.getByText('7,00 €')).toBeInTheDocument();
expect(
screen.getByText(
'Gibst du 2 Räder ab und verkaufst davon ein Rad für 150,00 €, bekommst du 131,00 € ' +
'(150,00 € − 15,00 € Provision − 4,00 € Annahmegebühr).'
)
).toBeInTheDocument();
expect(screen.getByText('Bis zu 25 Artikel pro Verkäufer')).toBeInTheDocument();
expect(screen.getByText(/online Preise vorschlagen/)).toBeInTheDocument();
expect(screen.getByText('Abholung')).toBeInTheDocument();
// Fees, times, what applies, what is possible
expect([...container.querySelectorAll('h4')].map((h) => h.textContent)).toEqual([
'Gebühren',
'Abgabe & Abholung',
'Das gilt für dich',
'Das ist möglich',
]);
});

it('leaves out the example and what is not offered when compact', () => {
it('leaves out the example when compact, and never names what is not offered', () => {
render(
<SellerConditions
compact
Expand All @@ -47,11 +61,11 @@ describe('SellerConditions', () => {
);
expect(screen.getByText(/10 % Provision/)).toBeInTheDocument();
expect(screen.queryByText('Rechenbeispiel')).not.toBeInTheDocument();
expect(screen.queryByText('Keine Rabatte während des Basars')).not.toBeInTheDocument();
expect(screen.queryByText(/Keine Rabatte|Kein Verhandeln/)).not.toBeInTheDocument();
expect(screen.getByText(/online Preise vorschlagen/)).toBeInTheDocument();
});

it('names required details, private sellers, fixed data and late questions', () => {
it('names required details, ID, private sellers and late questions, details on request', () => {
render(
<SellerConditions
event={{
Expand All @@ -66,15 +80,17 @@ describe('SellerConditions', () => {
}}
/>
);
expect(screen.getByText('Pflichtangaben für jeden Artikel: Rahmennummer')).toBeInTheDocument();
expect(screen.getByText('Pflichtangaben je Artikel: Rahmennummer')).toBeInTheDocument();
expect(screen.getByText(/Nur für Privatleute/)).toBeInTheDocument();
expect(screen.getByText(/Bring deinen Ausweis mit/)).toBeInTheDocument();
expect(screen.getByText(/Ausweis mitbringen/)).toBeInTheDocument();
expect(screen.getByText('Mehr dazu').closest('details')).not.toHaveAttribute('open');
expect(screen.getByText(/Käufer können während des Basars/)).toBeInTheDocument();
});

it('says so when there are no fees', () => {
render(<SellerConditions event={{ commission: 0 }} />);
render(<SellerConditions event={{ commission: 0, features: { discounts: false } }} />);
expect(screen.getByText(/Keine Gebühren/)).toBeInTheDocument();
expect(screen.queryByText('Rechenbeispiel')).not.toBeInTheDocument();
expect(screen.queryByText('Das ist möglich')).not.toBeInTheDocument();
});
});
97 changes: 45 additions & 52 deletions src/components/events/SellerConditions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import {
describeSellerFees,
describeSellerRules,
describeSellerSchedule,
formatSignedEuro,
type SellerConditionsEvent,
} from '../../lib/sellerFees';
import { resolveEventFeatures } from '../../shared/eventFeatures';
import { useCategoryFieldDefinitions } from '../../hooks/useCategoryFields';
import { cn, formatPriceDE } from '../../lib/utils';
import { cn } from '../../lib/utils';
import { useTranslation } from 'react-i18next';
import type { Id } from '../../lib/api/types';
import { FeeGroupList, MyFeeGroup } from './FeeGroups';

/**
* What sellers agree to at a bazaar: fees with a worked example, item limit, price
* features and hand-in/pickup times. Shown before registering and to registered
* sellers; `compact` (bazaar page sidebar) leaves out the example and what the
* bazaar does not offer.
* What sellers agree to at a bazaar, only what applies (#303): fees with a worked example
* that fits the kind of bazaar, hand-in and pickup times, what sellers must do and what
* they can do. Shown before registering and to registered sellers; `compact` (bazaar page
* sidebar) leaves out the example.
*/
export function SellerConditions({
event,
Expand All @@ -36,16 +34,9 @@ export function SellerConditions({
eventId?: Id<'events'>;
}) {
const { t } = useTranslation('events');
const { intakeFee, maxFeesPerSeller } = resolveEventFeatures(event);
const { lines, example } = describeSellerFees({
commission: event.commission,
intakeFee,
maxFeesPerSeller,
});
const { lines, example } = describeSellerFees(event);
const fieldDefinitions = useCategoryFieldDefinitions();
const rules = describeSellerRules(event, fieldDefinitions).filter(
(rule) => !compact || rule.allowed
);
const { duties, options } = describeSellerRules(event, fieldDefinitions);
const schedule = describeSellerSchedule(event);
const groups = describeFeeGroups(event);

Expand Down Expand Up @@ -73,45 +64,16 @@ export function SellerConditions({
{example && !compact && (
<div className="mt-3 rounded-md border bg-background p-3 text-sm">
<p className="font-medium">{t('conditions.example')}</p>
<p className="mb-2 text-muted-foreground">{example.intro}</p>
<table className="w-full tabular-nums">
<tbody>
{example.rows.map((row) => (
<tr key={row.label}>
<td className="py-0.5 pr-3">{row.label}</td>
<td
className={cn(
'py-0.5 text-right whitespace-nowrap',
row.amount < 0 && 'text-red-600 dark:text-red-400',
row.credit && 'text-emerald-700 dark:text-emerald-400'
)}
>
{formatSignedEuro(row.amount)}
</td>
</tr>
))}
<tr className="border-t font-semibold">
<td className="pt-1.5 pr-3">
{example.total >= 0 ? t('conditions.youGet') : t('conditions.youPay')}
</td>
<td className="pt-1.5 text-right whitespace-nowrap">
{formatPriceDE(Math.abs(example.total))} €
</td>
</tr>
</tbody>
</table>
<p className="text-muted-foreground">{example.text}</p>
{example.groups.map((group) => (
<p key={group} className="mt-1 text-muted-foreground">
{group}
</p>
))}
</div>
)}
</ConditionsSection>

<ConditionsSection title={t('conditions.itemsAndPrices')}>
<ul className="space-y-2">
{rules.map((rule) => (
<ConditionLine key={rule.text} allowed={rule.allowed} text={rule.text} />
))}
</ul>
</ConditionsSection>

{(schedule.rows.length > 0 || schedule.note) && (
<ConditionsSection title={schedule.title}>
{schedule.rows.length > 0 && (
Expand All @@ -131,6 +93,31 @@ export function SellerConditions({
)}
</ConditionsSection>
)}

{[
{ key: 'duties', rules: duties },
{ key: 'options', rules: options },
].map(
({ key, rules }) =>
rules.length > 0 && (
<ConditionsSection key={key} title={t(`conditions.${key}` as 'conditions.duties')}>
<ul className="space-y-2">
{rules.map((rule) => (
<ConditionLine key={rule.text} allowed={rule.allowed} text={rule.text}>
{rule.details && (
<details className="group">
<summary className="cursor-pointer text-xs text-muted-foreground underline-offset-2 hover:underline">
{t('conditions.details')}
</summary>
<p className="mt-1 text-xs text-muted-foreground">{rule.details}</p>
</details>
)}
</ConditionLine>
))}
</ul>
</ConditionsSection>
)
)}
</div>
</div>
);
Expand All @@ -151,10 +138,13 @@ function ConditionLine({
text,
allowed = true,
icon,
children,
}: {
text: string;
allowed?: boolean;
icon?: LucideIcon;
/** More about it below the text */
children?: ReactNode;
}) {
const Icon = icon ?? (allowed ? Check : X);
return (
Expand All @@ -165,7 +155,10 @@ function ConditionLine({
icon ? 'text-muted-foreground' : allowed && 'text-green-600'
)}
/>
{text}
<div className="min-w-0">
{text}
{children}
</div>
</li>
);
}
Loading
Loading