fix: opravy po review
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 21s
CI / Generate TypeScript types (pull_request) Successful in 47s
CI / Build server (push) Successful in 27s
CI / Server unit tests (pull_request) Successful in 20s
CI / Build server (pull_request) Successful in 27s
CI / Build client (pull_request) Successful in 40s
CI / Playwright E2E tests (pull_request) Successful in 1m20s
CI / Build and push Docker image (pull_request) Has been skipped
CI / Notify (pull_request) Has been skipped
CI / Build client (push) Successful in 4m13s
CI / Playwright E2E tests (push) Successful in 6m7s
CI / Build and push Docker image (push) Has been skipped
CI / Notify (push) Successful in 6s
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 21s
CI / Generate TypeScript types (pull_request) Successful in 47s
CI / Build server (push) Successful in 27s
CI / Server unit tests (pull_request) Successful in 20s
CI / Build server (pull_request) Successful in 27s
CI / Build client (pull_request) Successful in 40s
CI / Playwright E2E tests (pull_request) Successful in 1m20s
CI / Build and push Docker image (pull_request) Has been skipped
CI / Notify (pull_request) Has been skipped
CI / Build client (push) Successful in 4m13s
CI / Playwright E2E tests (push) Successful in 6m7s
CI / Build and push Docker image (push) Has been skipped
CI / Notify (push) Successful in 6s
This commit is contained in:
@@ -17,6 +17,7 @@ type Props = {
|
||||
payerLogin: string;
|
||||
bankAccount: string;
|
||||
bankAccountHolder: string;
|
||||
groupId?: string;
|
||||
};
|
||||
|
||||
function sanitizeAmount(value: string): string {
|
||||
@@ -32,7 +33,7 @@ function parseAmount(s: string): number | null {
|
||||
return Math.round(n * 100) / 100;
|
||||
}
|
||||
|
||||
export default function PayForGroupModal({ isOpen, onClose, group, payerLogin, bankAccount, bankAccountHolder }: Readonly<Props>) {
|
||||
export default function PayForGroupModal({ isOpen, onClose, group, payerLogin, bankAccount, bankAccountHolder, groupId }: Readonly<Props>) {
|
||||
const [diners, setDiners] = useState<DinerEntry[]>([]);
|
||||
const [tipTotal, setTipTotal] = useState('');
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -63,10 +64,16 @@ export default function PayForGroupModal({ isOpen, onClose, group, payerLogin, b
|
||||
const totalPeople = includedNonPayers.length + 1; // +1 for payer
|
||||
return Math.round((tip / totalPeople) * 100) / 100;
|
||||
})();
|
||||
const payerTipShare = (() => {
|
||||
const tip = parseAmount(tipTotal);
|
||||
if (!tip) return 0;
|
||||
return Math.round((tip - tipPerPerson * includedNonPayers.length) * 100) / 100;
|
||||
})();
|
||||
|
||||
const getTotal = (d: DinerEntry): number => {
|
||||
const surcharge = parseAmount(d.surchargeAmount) ?? 0;
|
||||
return Math.round((d.baseAmount + surcharge + tipPerPerson) * 100) / 100;
|
||||
const tip = d.login === payerLogin ? payerTipShare : tipPerPerson;
|
||||
return Math.round((d.baseAmount + surcharge + tip) * 100) / 100;
|
||||
};
|
||||
|
||||
const handleInclude = useCallback((login: string, checked: boolean) => {
|
||||
@@ -112,7 +119,7 @@ export default function PayForGroupModal({ isOpen, onClose, group, payerLogin, b
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await generateQr({
|
||||
body: { recipients, bankAccount, bankAccountHolder },
|
||||
body: { recipients, bankAccount, bankAccountHolder, ...(groupId ? { groupId } : {}) },
|
||||
});
|
||||
if (response.error) {
|
||||
setError((response.error as any).error || 'Nastala chyba při generování QR kódů');
|
||||
@@ -203,7 +210,7 @@ export default function PayForGroupModal({ isOpen, onClose, group, payerLogin, b
|
||||
</div>
|
||||
</td>
|
||||
<td className="text-end">
|
||||
{tipPerPerson > 0 ? `${tipPerPerson} Kč` : '—'}
|
||||
{(() => { const s = isPayer ? payerTipShare : tipPerPerson; return s > 0 ? `${s} Kč` : '—'; })()}
|
||||
</td>
|
||||
<td className="text-end fw-bold">
|
||||
{`${total} Kč`}
|
||||
|
||||
Reference in New Issue
Block a user