Skip to Content
BBRICKSv0.7.4
PR PortalCampaigns

useCommissionText

commissionText bound to the BricksProvider: the blocks' CommissionInput / CommissionRate words (with the provider's labels.commissionInput override), the provider's currency label and its language (or language). Call it in a component: const rate = useCommissionText(); rate('percent', '10') gives "10% of sale", the same as <CommissionRate form="long"> beside it. options still win, per call.

import { useCommissionText } 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>;
}

Signature

function useCommissionText(language?: Lang | undefined): CommissionTextFormatter

Parameters

Prop

Type

Returns

CommissionTextFormatter

useBricks · useLanguage · PageGrid · CommissionChangeForm · Card · ChangePreview · AffiliateProgramCard · CampaignChallenges · CampaignChangeRequests

Source

src/pr/programs/commissionText.ts (line 57) on GitHub.

On this page