Skip to Content
BBRICKSv0.7.4
PR PortalChallenges

ChallengeGiftPicker

The challenge builder's gift reward (v3 mock step 4, "From confirmed gift stock only"): a select of the brand's confirmed gifts with the units left (a gift with none left is shown, not choosable), the cost per winner held from the wallet, and a warning when fewer are left than the challenge's winners. With no confirmed stock, it says why a gift challenge can't go live yet and links to the gift stock.

import { ChallengeGiftPicker } from '@ergasti/bricks';

Examples

Gift reward

Only the brand's confirmed gift stock can be a challenge's reward: units left, the cost per winner, and a warning when fewer are left than winners.

Code
import { useState } from 'react';
import { ChallengeGiftPicker, type ConfirmedGift } from '@ergasti/bricks';

const stock: ConfirmedGift[] = [
  { id: 'serum', name: 'Serum gift set', cost: '650.00', left: 42 },
  { id: 'lip', name: 'Lip oil bundle', cost: '420.00', left: 0 },
  { id: 'mask', name: 'Mask kit', cost: '300.00', left: 4 },
];

function GiftReward() {
  const [gift, setGift] = useState<string | number | null>('serum');
  return (
    <div style={{ maxWidth: 560 }}>
      <ChallengeGiftPicker stock={stock} value={gift} onChange={setGift} brand="Glow Lab" needed={10} onOpenStock={() => {}} money={{ decimals: 'auto' }} />
    </div>
  );
}

No confirmed stock

A gift challenge can't go live until its gifts are counted and confirmed.

Code
import { ChallengeGiftPicker, type ConfirmedGift } from '@ergasti/bricks';

const stock: ConfirmedGift[] = [
  { id: 'serum', name: 'Serum gift set', cost: '650.00', left: 42 },
  { id: 'lip', name: 'Lip oil bundle', cost: '420.00', left: 0 },
  { id: 'mask', name: 'Mask kit', cost: '300.00', left: 4 },
];

function NoStock() {
  return <div style={{ maxWidth: 560 }}><ChallengeGiftPicker stock={[]} value={null} onChange={() => {}} brand="Nile Threads" onOpenStock={() => {}} /></div>;
}

Props

Prop

Type

Labels

Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key prChallengeGiftPicker, or with the component's own prop where it has one. A {name} is a value the component fills in.

prChallengeGiftPicker
KeyEnglishArabic
labelGiftالهدية
chooseChoose a giftاختار هدية
left{n} leftفاضل {n}
noneNo gifts leftمفيش هدايا فاضلة
costCost per winnerالتكلفة لكل كسبان
inclincl. deliveryشامل التوصيل
shortOnly {left} left for {need} winners. Lower the winners or ask the brand to send more.فاضل {left} بس لـ {need} كسبان. قلّل الكسبانين أو اطلب من البراند يبعت تاني.
empty{b} has no confirmed gift stock yet. A challenge with gifts can’t go live until its gifts are counted and confirmed.{b} معندوش مخزون هدايا متأكد منه لسه. التحدي اللي فيه هدايا مش هيشتغل غير لما هداياه تتعد وتتأكد.
stockGift stockمخزون الهدايا
soldOut{name} has no gifts left. Choose another gift.{name} مفيش منها هدايا فاضلة. اختار هدية تانية.

Design guidance

How the BRICKS design system uses ChallengeGiftPicker. Written in docs/content/components/ChallengeGiftPicker.md; the props above are read from the code, which wins where the two disagree.

The challenge builder's gift reward field: a select of the brand's confirmed gifts with units left, the cost per winner held from the wallet, and a warning when fewer are left than the challenge's winners; use it in the builder's Reward step when the reward is a gift.

It is the v3 PR mock's step 4 "From confirmed gift stock only". A gift with none left is listed but not choosable. With no confirmed stock it says why a gift challenge can't go live yet and links to the brand's gift stock.

Anatomy

  1. Field (.kit-field.kit-pr-gp): label "Gift".
  2. Select: "Choose a gift" placeholder, then "Serum gift set · 42 left", "Lip oil bundle · No gifts left" (disabled).
  3. Hint (chosen): "Cost per winner" (MoneyNote term) EGP 650 incl. delivery.
  4. Error lines: shortage ("Only 4 left for 10 winners. Lower the winners or ask the brand to send more.") or sold out, each with "Gift stock →".
  5. Empty (no usable stock): a status paragraph and the link.

Variants

CaseConditionLook
Chosenvalue with units leftSelect and cost hint.
Shortchosen left < neededHint plus red warning.
Sold outvalue points to a gift with 0 leftaria-invalid, "{name} has no gifts left. Choose another gift."
No stockno gift with units leftExplanation and "Gift stock →" (story NoStock).

States

As above; focus uses the kit field ring.

Types

ConfirmedGift (stock): { id, name, cost, left }, confirmed units only.

Usage

const stock: ConfirmedGift[] = [
  { id: 'serum', name: 'Serum gift set', cost: '650.00', left: 42 },
  { id: 'lip', name: 'Lip oil bundle', cost: '420.00', left: 0 },
  { id: 'mask', name: 'Mask kit', cost: '300.00', left: 4 },
];

<ChallengeGiftPicker
  stock={stock}
  value={draft.giftId}
  onChange={(id) => setDraft({ ...draft, giftId: id })}
  brand="Glow Lab"
  needed={draft.winners}
  onOpenStock={() => navigate('/gifts?brand=glow')}
  money={{ decimals: 'auto' }}
/>

Where it appears

Guidelines

Do

  • Pass only confirmed units (not a brand's claim).
  • Pass needed so a shortage is caught before launch.

Don't

  • Don't hide sold-out gifts; they show why they can't be chosen.

RTL and Arabic

  • Field mirrors; the arrow flips. "اختار هدية", "فاضل 42", "مفيش هدايا فاضلة".

Tokens

Kit field tokens; error lines use .kit-field-err (--bad).

Accessibility

  • A native <select> with a <label>; hint and errors in aria-describedby; aria-invalid for a sold-out choice; the empty explanation is role="status".

Found in the source

  • Roles in the markup: status.
  • ARIA attributes set: aria-hidden, aria-labelledby, aria-invalid, aria-describedby.
  • Its tests cover: “Arabic: the label and the units left”.

Read from the component's source and tests. See Accessibility for the patterns the library follows.

See also: Money · MoneyNote · useLanguage · PrIcon · BrandRequestCard · BuilderStepCard · ChallengeAudienceFields · ChallengeBasicsFields

Source

src/pr/challenges/ChallengeGiftPicker.tsx (line 67) on GitHub.

On this page