Skip to Content
BBRICKSv0.7.4
PR PortalCampaigns

CommissionChangeForm

A campaign's "Change the commission" form (the v3 mock's P.program form): how creators earn (% of sale or a fixed amount per item, as two choice cards), the value with the 0–50 % rule said under it, the Tier bonus (an open decision), an optional message to the brand, then Cancel / "Save and notify {brand}". Controlled; Save is enabled once the value is valid and differs from current. Pair it with a ChangePreview ("What changes") fed from the same value and commissionChangeError.

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

Examples

Change the commission

% of sale or a fixed amount per item, the value (above 0 and up to COMMISSION_MAX_PERCENT, 50 %, with 2 decimals, said under the field; maxPercent changes the limit), the Tier bonus (an open decision), a message to the brand, then Save and notify once something changed. "What changes" beside it reads the same value: useCommissionText writes both rates with the provider's currency and commissionChangeError the same rule. Type 60, or ١٢٫٥ on an Arabic keyboard.

Code
import { useState } from 'react';
import { COMMISSION_MAX_PERCENT, Card, ChangePreview, CommissionChangeForm, PageGrid, commissionChangeError, useCommissionText, type CommissionChange } from '@ergasti/bricks';

const CURRENT = { kind: 'percent' as const, value: '10' };

function ChangeTheCommission() {
  const [value, setValue] = useState<CommissionChange>({ ...CURRENT, note: '' });
  const rate = useCommissionText();
  const error = commissionChangeError(value.kind, value.value, 'en', { maxPercent: COMMISSION_MAX_PERCENT });
  const changed = value.kind !== CURRENT.kind || Number(value.value) !== Number(CURRENT.value);
  return (
    <PageGrid split="7-5" align="start">
      <CommissionChangeForm value={value} onChange={setValue} current={CURRENT} brandName="Glow Lab" onSave={() => {}} onCancel={() => {}} />
      <Card title="What changes">
        <ChangePreview from={rate(CURRENT.kind, CURRENT.value)} to={rate(value.kind, value.value)} changed={changed} error={error ?? undefined}
          note="Applies to orders placed after you save. Orders already placed keep the old rate." />
      </Card>
    </PageGrid>
  );
}

Rates in words

commissionText(kind, value, language) for a string prop outside a component: "10% of sale", "EGP 50 per item", and in Arabic; currency takes another currency word (it defaults to EGP). In a component, useCommissionText() takes the BricksProvider's currency and words.

Code (not run)
import { commissionText } from '@ergasti/bricks';

function RatesInWords() {
  return (
    <ul>
      <li>{commissionText('percent', '10', 'en')}</li>
      <li>{commissionText('per_item', '50.00', 'en')}</li>
      <li dir="rtl">{commissionText('percent', '12.5', 'ar')}</li>
      <li dir="rtl">{commissionText('per_item', '50', 'ar')}</li>
    </ul>
  );
}

In Arabic

Pinned to Arabic
Code
import { useState } from 'react';
import { CommissionChangeForm, type CommissionChange } from '@ergasti/bricks';

function Arabic() {
  const [value, setValue] = useState<CommissionChange>({ kind: 'per_item', value: '50', note: '' });
  return <div style={{ maxWidth: 600 }}><CommissionChangeForm value={value} onChange={setValue} current={{ kind: 'per_item', value: '50' }} brandName="Glow Lab" onSave={() => {}} onCancel={() => {}} /></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 prCommissionChange, or with the component's own prop where it has one. A {name} is a value the component fills in.

prCommissionChange
KeyEnglishArabic
earnHow creators earnصانع المحتوى بيكسب إزاي
pct% of sale% من البيع
pctDA share of each delivered orderنسبة من كل طلب اتسلّم
fixedFixed per itemمبلغ ثابت للقطعة
fixedDA set amount per item soldمبلغ محدد لكل قطعة اتباعت
valuePctCommission (%)العمولة (%)
valueFixedCommission ({currency} per item)العمولة ({currency} للقطعة)
tierBonusTier bonusبونص المستوى
tierHintDepends on what a tier gives creators.بيعتمد على المستوى بيدّي صنّاع المحتوى إيه.
noteMessage to the brandرسالة للبراند
optional(optional)(اختياري)
notePhSent with the notificationهتتبعت مع الإشعار
cancelCancelإلغاء
saveSave and notify {brand}احفظ وبلّغ {brand}
workingSaving…بنحفظ…
errPctEnter a value above 0 and up to {max}%.اكتب رقم أكبر من صفر ولحد {max}%.
errFixedEnter a value above 0.اكتب رقم أكبر من صفر.

Design guidance

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

A campaign's "Change the commission" form: % of sale or a fixed amount per item, the value with its 0–50 % rule, the tier bonus, an optional message to the brand, then "Save and notify {brand}"; pair it with a ChangePreview.

CommissionChangeForm is the PR v3 mock's P.program form under "Change the commission". How creators earn is a pair of choice cards ("% of sale" · "A share of each delivered order", rasp; "Fixed per item" · "A set amount per item sold", sky). The value is checked against the PR rule, exported as commissionChangeError (above 0 and up to COMMISSION_MAX_PERCENT = 50 %, or above 0 per item, both with at most 2 decimals); use the same function for the ChangePreview beside it. The Tier bonus shows the open decision R10. Save stays disabled until the value is valid and differs from current, and onSave gets the value with ASCII digits.

Anatomy

  1. Card (with card, the default) or bare fields (card={false}) in .kit-pr-ccf.
  2. How creators earn: a FormField as="group" around a two-column ChoiceGroup.
  3. Commission: "Commission (%)" or "Commission (EGP per item)", an LTR text input (inputMode="decimal"), the rule as its error.
  4. Tier bonus: hint "Depends on what a tier gives creators.", then tierBonus or the butter "Open · R10" tag.
  5. Message to the brand (optional): a textarea, placeholder "Sent with the notification".
  6. Error line (with error), then actions: Cancel (default, with onCancel) and Save and notify Glow Lab (ink).

Variants

PropValueLookWhen to use
value.kindpercent"% of sale" card chosen, "Commission (%)"Share of each delivered order
per_item"Fixed per item" chosen, "Commission (EGP per item)"A set amount per item
cardtrue (default)Inside its own CardThe campaign page (the mock)
falseFields and buttons onlyInside a drawer or a modal
maxPercentdefault '50'Changes the rule and its messageA different PR limit

Switching the kind sets the value to the current one for the current kind, else startValues (default 10 % / 50 per item).

States

StateTrigger
Unchangedvalue equals current: Save disabled
Invalidvalue fails the rule: "Enter a value above 0 and up to 50%." / "Enter a value above 0." under the field; Save disabled
Readyvalid and different from current: Save enabled
Busybusy: Save disabled, aria-busy, reads "Saving…"
Errorerror: role="alert" line above the buttons

Usage

import { useState } from 'react';
import { Card, ChangePreview, CommissionChangeForm, PageGrid, commissionChangeError, useCommissionText, type CommissionChange } from '@ergasti/bricks';

const current = { kind: 'percent' as const, value: '10' };

export function ChangeTheCommission() {
  const [change, setChange] = useState<CommissionChange>({ ...current, note: '' });
  const rate = useCommissionText();
  const error = commissionChangeError(change.kind, change.value, 'en');
  const changed = change.kind !== current.kind || Number(change.value) !== Number(current.value);
  return (
    <PageGrid split="7-5" align="start">
      <CommissionChangeForm value={change} onChange={setChange} current={current} brandName="Glow Lab" onSave={(v) => console.log('save', v)} onCancel={() => {}}
        decisions={[{ id: 'R10', question: 'What a tier gives creators' }]} />
      <Card title="What changes">
        <ChangePreview from={rate(current.kind, current.value)} to={rate(change.kind, change.value)} changed={changed} error={error ?? undefined}
          note="Applies to orders placed after you save. Orders already placed keep the old rate." />
      </Card>
    </PageGrid>
  );
}
// In a drawer: no card of its own, a failed save
import { useState } from 'react';
import { CommissionChangeForm, type CommissionChange } from '@ergasti/bricks';

export function CommissionInDrawer() {
  const [change, setChange] = useState<CommissionChange>({ kind: 'per_item', value: '60', note: '' });
  return <CommissionChangeForm card={false} value={change} onChange={setChange} current={{ kind: 'per_item', value: '50' }} brandName="Glow Lab" onSave={() => {}} error="Couldn’t save. Try again." />;
}

Where it appears

  • PR Portal › Affiliate programs › a brand's campaign › "Change the commission" (the mock's P.program), beside "What changes" and the Status card. Screen: PR · A brand's campaign.
  • Reached from Brand detail › Affiliate program › Edit program.
  • Dashboard screen: PrPrograms.

Guidelines

Do

  • Feed ChangePreview from the same value and commissionChangeError, so the rule reads the same twice.
  • Pass decisions so the R10 tag can show its question.
  • Save the ASCII value onSave gives, and notify the brand with note.

Don't

  • Don't validate with your own rule; use commissionChangeError with the same maxPercent.
  • Don't make Save raspberry: PR Portal commits are ink.
  • Don't add a tier bonus input before R10 is decided; leave the tag.

RTL and Arabic

Cards, fields and buttons mirror; the value stays dir="ltr", the note is dir="auto". Arabic-Indic digits ("١٢٫٥") are read as digits. Arabic: "صانع المحتوى بيكسب إزاي", "% من البيع", "مبلغ ثابت للقطعة", "بونص المستوى", "رسالة للبراند (اختياري)", "احفظ وبلّغ {brand}". Override with labels or labels.prCommissionChange.

Tokens

--line, --card, --ink, --ink-3, --rasp, --focus-ring, --color-control-border-hover (choice cards), --butter, --butter-ink (R10 tag), Card tokens.

Accessibility

  • The kind is a ChoiceGroup: role="radiogroup" named "How creators earn", one tab stop, arrows move and choose, Home / End jump.
  • Fields are FormFields with labels; the rule is the field's error.
  • Save sets aria-busy while saving; the error is role="alert".
  • The R10 tag is focusable for its question when one is given.

Found in the source

  • Roles in the markup: alert.
  • ARIA attributes set: aria-busy.

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

See also: Button · Card · FormField · useBricks · useLanguage · DecisionTag · useCommissionText · PageGrid · AffiliateProgramCard · CampaignChallenges · CampaignChangeRequests · CustomerAffiliatesCard

Source

src/pr/programs/CommissionChangeForm.tsx (line 98) on GitHub.

On this page