AdjustWalletDialog
The brand page's "Adjust wallet" modal (the PR mock v3's adjWallet): for mistakes only, an amount in the provider's currency (a minus sign takes money out; not 0; up to two decimals) and a required reason, with what the wallet holds after it when available is given. Money is exact: the amount is parsed in cents and onSave gets a 2-dp string. On the kit Modal (focus trap, Escape, scrim). Controlled by open; the fields reset each time it opens, before the first paint. The amount field asks for a text keyboard (inputMode="text"): a phone's decimal keypad has no minus key, and a minus sign is how PR takes money out.
import { AdjustWalletDialog } from '@ergasti/bricks';Examples
Change PR owner
The select starts on the current owner and marks you; saving the same person says so instead of calling onSave. value is null for a brand nobody owns yet (or an id no longer in owners): the select then starts on "Choose the new owner". Controlled by open; the choice resets each time it opens.
Code
import { Button, ChangeOwnerDialog } from '@ergasti/bricks';
import { useState } from 'react';
const PRS = [{ id: 'mona', name: 'Mona Adel' }, { id: 'farida', name: 'Farida Nabil' }, { id: 'ahmed', name: 'Ahmed Samy' }];
function ChangeOwner() {
const [open, setOpen] = useState(false);
const [owner, setOwner] = useState<string | number | null>(null);
return (
<div style={{ display: 'grid', gap: 10, justifyItems: 'start' }}>
<Button onClick={() => setOpen(true)}>Change</Button>
<small>Owner: {PRS.find((p) => p.id === owner)?.name ?? 'nobody yet'}</small>
<ChangeOwnerDialog open={open} onClose={() => setOpen(false)} brandName="Glow Lab" owners={PRS} value={owner} meId="mona" onSave={(id) => { setOwner(id); setOpen(false); }} />
</div>
);
}Adjust wallet
An amount that is not 0 with up to two decimals (a minus sign takes money out) and a reason. The field asks for a text keyboard, so a phone shows the minus key. The amount is parsed in cents by parseWalletAdjustment (exported for your own checks: "-390.1" gives "-390.10"; 0, "1.005" and "+-5" give null), so onSave gets an exact 2-dp string; with available the dialog shows what the wallet holds after it. Try 0, 1.005 or −390.10.
Code
import { AdjustWalletDialog, Button, type WalletAdjustment } from '@ergasti/bricks';
import { useState } from 'react';
function AdjustWallet() {
const [open, setOpen] = useState(false);
const [last, setLast] = useState<WalletAdjustment | null>(null);
return (
<div style={{ display: 'grid', gap: 10, justifyItems: 'start' }}>
<Button onClick={() => setOpen(true)}>Adjust wallet</Button>
<small>{last ? `Saved ${last.amount}: ${last.reason}` : 'Nothing saved yet'}</small>
<AdjustWalletDialog open={open} onClose={() => setOpen(false)} brandName="Glow Lab" available="43390.00" money={{ decimals: 'auto' }} onSave={(a) => { setLast(a); setOpen(false); }} />
</div>
);
}TRNDR fee
0 to BRAND_FEE_MAX (50) % with up to two decimals, checked by parseBrandFee ("7.5" gives "7.50", "50.01" gives null). "Use default (5%)" shows while the brand has its own fee, and saving an empty field uses the default too; without onUseDefault an empty field is an error. A failed save shows error; busy locks the buttons.
Code
import { BrandFeeDialog, Button } from '@ergasti/bricks';
import { useState } from 'react';
function Fee() {
const [open, setOpen] = useState(false);
const [fee, setFee] = useState<string | null>('7.5');
return (
<div style={{ display: 'grid', gap: 10, justifyItems: 'start' }}>
<Button onClick={() => setOpen(true)}>Change fee</Button>
<small>Fee: {fee === null ? '5% (default)' : `${fee}%`}</small>
<BrandFeeDialog open={open} onClose={() => setOpen(false)} brandName="Glow Lab" value={fee} defaultFee="5" onSave={(v) => { setFee(v); setOpen(false); }} onUseDefault={() => { setFee(null); setOpen(false); }} />
</div>
);
}Arabic
Code
import { AdjustWalletDialog, Button } from '@ergasti/bricks';
import { useState } from 'react';
function Arabic() {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)}>عدّل المحفظة</Button>
<AdjustWalletDialog open={open} onClose={() => setOpen(false)} brandName="Glow Lab" available="43390.00" onSave={() => setOpen(false)} language="ar" />
</>
);
}Props
Prop
Type
Labels
Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key prAdjustWallet, or with the component's own prop where it has one. A {name} is a value the component fills in.
| Key | English | Arabic |
|---|---|---|
title | Adjust {brand}'s wallet | عدّل محفظة {brand} |
sub | For mistakes only. Use a minus sign to take money out. Brands top up by card themselves. | للأخطاء بس. حط علامة سالب علشان تسحب فلوس. البراندات بتشحن بالكارت بنفسها. |
amount | Amount ({currency}) | المبلغ ({currency}) |
amountPh | e.g. 500 or -500 | مثلاً 500 أو -500 |
reason | Reason | السبب |
reasonPh | What was wrong and why | إيه اللي كان غلط وليه |
after | Available after this: | المتاح بعد كده: |
cancel | Cancel | إلغاء |
save | Save adjustment | احفظ التعديل |
saving | Saving… | بنحفظ… |
amountErr | Enter an amount that is not 0, with up to two decimals (a minus sign takes money out). | اكتب مبلغ مش صفر، لحد رقمين بعد العلامة (علامة السالب بتسحب فلوس). |
reasonErr | Add a reason. | اكتب السبب. |
Design guidance
How the BRICKS design system uses AdjustWalletDialog. Written in docs/content/components/AdjustWalletDialog.md; the props above are read from the code, which wins where the two disagree.
A modal where PR corrects a brand's wallet by a signed amount with a required reason; use it for mistakes only, from the brand's wallet card.
AdjustWalletDialog is the PR v3 mock's adjWallet overlay on Brand detail ("Adjust Glow Lab's wallet"), which the design system used to compose by hand. The hint sets the rule: "For mistakes only. Use a minus sign to take money out. Brands top up by card themselves." The amount is parsed exactly in cents (parseWalletAdjustment, exported): not 0, up to two decimals, a leading +, - or −, Arabic-Indic digits and the Arabic decimal mark accepted. With available it shows what the wallet holds after the change. onSave gets { amount, reason } with a signed 2-dp string ("500.00", "-120.50").
Anatomy
- Modal: the kit
Modal(.kit-pr-bdlg): title "Adjust Glow Lab's wallet", the rule as its hint, close ×, scrim. - Amount: "Amount (EGP)" (the provider's currency), a full-width LTR text input, placeholder "e.g. 500 or -500". Its hint, once the amount is valid and
availableis set: "Available after this: EGP 43,890" (for +500 on EGP 43,390) (MoneyNote figure="wallet_available"+Money slot="brandDetail.figures"). - Reason: a required 3-row textarea, placeholder "What was wrong and why", min 84px, resizable.
- Footer: an error alert (with
error) at the start, Cancel (default), Save adjustment (ink).
Variants
AdjustWalletDialog has no visual variants.
| Prop | Effect |
|---|---|
available set | The amount's hint shows the balance after the adjustment |
available unset | No after-figure |
money | How the after-figure is shown (e.g. { decimals: 'auto' } for "EGP 43,890"), over the provider's brandDetail.figures slot |
States
| State | Trigger |
|---|---|
| Closed | open={false} |
| Open, fresh | open becomes true: amount, reason and the "tried" flag reset before the first paint |
| After-figure | a valid amount with available set |
| Invalid amount | Save with 0, empty, more than two decimals ("1.005") or two signs ("+-5"): "Enter an amount that is not 0, with up to two decimals (a minus sign takes money out)." |
| Missing reason | Save with a blank reason: "Add a reason." |
| Busy | busy: Save reads "Saving…" and is disabled |
| Error | error: role="alert" line in the footer |
Usage
import { useState } from 'react';
import { AdjustWalletDialog, BrandWalletCard, type WalletAdjustment } from '@ergasti/bricks';
export function BrandWallet() {
const [dialog, setDialog] = useState<'adjust' | null>(null);
const [available, setAvailable] = useState('43390.00');
const [last, setLast] = useState<WalletAdjustment | null>(null);
return (
<>
<BrandWalletCard available={available} held="18450.00" balance="61840.00" leftPercent={17} health="ok" feePercent="5" feeIsDefault
onAdjust={() => setDialog('adjust')} onChangeFee={() => {}} topUpMethods="card" money={{ decimals: 'auto' }} />
<AdjustWalletDialog
open={dialog === 'adjust'}
onClose={() => setDialog(null)}
brandName="Glow Lab"
available={available}
money={{ decimals: 'auto' }}
onSave={(adjustment) => { setLast(adjustment); setDialog(null); }}
/>
{last && <small>Adjusted by {last.amount}: {last.reason}</small>}
</>
);
}// The same exact parse, for your own checks
import { parseWalletAdjustment } from '@ergasti/bricks';
const out = parseWalletAdjustment('-390.1'); // "-390.10"
const zero = parseWalletAdjustment('0'); // null
const tooFine = parseWalletAdjustment('1.005'); // nullWhere it appears
- PR Portal › Brand detail › Wallet card › "Adjust wallet" (the mock's
adjWallet). Screen: PR · Brand. - Dashboard screen: PrBrand.
Guidelines
Do
- Pass
availableso PR sees the result before saving. - Send
amountto the server as the stringonSavegives; it is already exact. - Log the reason with the adjustment (the mock writes it to the activity log).
Don't
- Don't offer it as a top-up: brands top up by card themselves.
- Don't swap the field for
type="number": the text keyboard keeps the minus key on phones. - Don't make Save raspberry: the PR Portal commits in
ink.
RTL and Arabic
The modal mirrors; the amount stays dir="ltr" so the sign leads, the reason is dir="auto". Arabic digits ("٥٠٠", "٫") parse as the same amount. Arabic copy: "عدّل محفظة {brand}", "المبلغ ({currency})", "السبب", "المتاح بعد كده:", "احفظ التعديل". Override with labels or labels.prAdjustWallet.
Tokens
--line, --card, --ink, --rasp, --radius-md, --focus-ring, --min-touch-target, --dlg-title-fs (Modal); Money / MoneyNote tokens for the after-figure.
Accessibility
- Kit Modal:
role="dialog",aria-modal="true", named by the title; focus trapped, Escape and scrim close, focus returns to the opener;inertRef(or the page) is inert. - Both fields are
FormFields with labels; errors are tied to the field; the reason isrequired. - The amount asks for
inputMode="text",autoComplete="off". - The footer error is
role="alert".
Found in the source
- Roles in the markup:
alert.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
BrandWalletCard: opens it (onAdjust) and the fee dialog (onChangeFee).BrandFeeDialog: the brand's TRNDR fee.ChangeOwnerDialog: the other Brand detail dialog.
See also: Button · FormField · Modal · Money · MoneyNote · useBricks · useLanguage · BrandAvatar · BrandCell · BrandDetailHeader
Source
src/pr/brand/AdjustWalletDialog.tsx (line 85) on GitHub.