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
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.
| Key | English | Arabic |
|---|---|---|
earn | How creators earn | صانع المحتوى بيكسب إزاي |
pct | % of sale | % من البيع |
pctD | A share of each delivered order | نسبة من كل طلب اتسلّم |
fixed | Fixed per item | مبلغ ثابت للقطعة |
fixedD | A set amount per item sold | مبلغ محدد لكل قطعة اتباعت |
valuePct | Commission (%) | العمولة (%) |
valueFixed | Commission ({currency} per item) | العمولة ({currency} للقطعة) |
tierBonus | Tier bonus | بونص المستوى |
tierHint | Depends on what a tier gives creators. | بيعتمد على المستوى بيدّي صنّاع المحتوى إيه. |
note | Message to the brand | رسالة للبراند |
optional | (optional) | (اختياري) |
notePh | Sent with the notification | هتتبعت مع الإشعار |
cancel | Cancel | إلغاء |
save | Save and notify {brand} | احفظ وبلّغ {brand} |
working | Saving… | بنحفظ… |
errPct | Enter a value above 0 and up to {max}%. | اكتب رقم أكبر من صفر ولحد {max}%. |
errFixed | Enter 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
- Card (with
card, the default) or bare fields (card={false}) in.kit-pr-ccf. - How creators earn: a
FormField as="group"around a two-columnChoiceGroup. - Commission: "Commission (%)" or "Commission (EGP per item)", an LTR text input (
inputMode="decimal"), the rule as its error. - Tier bonus: hint "Depends on what a tier gives creators.", then
tierBonusor the butter "Open · R10" tag. - Message to the brand (optional): a textarea, placeholder "Sent with the notification".
- Error line (with
error), then actions: Cancel (default, withonCancel) and Save and notify Glow Lab (ink).
Variants
| Prop | Value | Look | When to use |
|---|---|---|---|
value.kind | percent | "% 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 | |
card | true (default) | Inside its own Card | The campaign page (the mock) |
false | Fields and buttons only | Inside a drawer or a modal | |
maxPercent | default '50' | Changes the rule and its message | A 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
| State | Trigger |
|---|---|
| Unchanged | value equals current: Save disabled |
| Invalid | value fails the rule: "Enter a value above 0 and up to 50%." / "Enter a value above 0." under the field; Save disabled |
| Ready | valid and different from current: Save enabled |
| Busy | busy: Save disabled, aria-busy, reads "Saving…" |
| Error | error: 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
ChangePreviewfrom the samevalueandcommissionChangeError, so the rule reads the same twice. - Pass
decisionsso the R10 tag can show its question. - Save the ASCII value
onSavegives, and notify the brand withnote.
Don't
- Don't validate with your own rule; use
commissionChangeErrorwith the samemaxPercent. - 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-busywhile saving; the error isrole="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.
Related
ChangePreview: "What changes" beside it.ProgramStatusCard: the Status card under the preview.CommissionInput: the brand dashboard's commission field.ChoiceGroup: the kind cards.
See also: Button · Card · FormField · useBricks · useLanguage · DecisionTag · useCommissionText · PageGrid · AffiliateProgramCard · CampaignChallenges · CampaignChangeRequests · CustomerAffiliatesCard
Source
src/pr/programs/CommissionChangeForm.tsx (line 98) on GitHub.