myoperator-ui 0.0.165 → 0.0.166
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +137 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8743,7 +8743,7 @@ export type {
|
|
|
8743
8743
|
{
|
|
8744
8744
|
name: "wallet-topup.tsx",
|
|
8745
8745
|
content: prefixTailwindClasses(`import * as React from "react";
|
|
8746
|
-
import {
|
|
8746
|
+
import { Ticket } from "lucide-react";
|
|
8747
8747
|
import { cn } from "../../../lib/utils";
|
|
8748
8748
|
import { Button } from "../button";
|
|
8749
8749
|
import { Input } from "../input";
|
|
@@ -8766,7 +8766,11 @@ function normalizeAmountOption(option: number | AmountOption): AmountOption {
|
|
|
8766
8766
|
* Format currency amount with symbol
|
|
8767
8767
|
*/
|
|
8768
8768
|
function formatCurrency(amount: number, symbol: string = "\u20B9"): string {
|
|
8769
|
-
|
|
8769
|
+
const hasDecimals = amount % 1 !== 0;
|
|
8770
|
+
return \`\${symbol}\${amount.toLocaleString("en-IN", {
|
|
8771
|
+
minimumFractionDigits: hasDecimals ? 2 : 0,
|
|
8772
|
+
maximumFractionDigits: hasDecimals ? 2 : 0,
|
|
8773
|
+
})}\`;
|
|
8770
8774
|
}
|
|
8771
8775
|
|
|
8772
8776
|
/**
|
|
@@ -8798,6 +8802,13 @@ export const WalletTopup = React.forwardRef<HTMLDivElement, WalletTopupProps>(
|
|
|
8798
8802
|
customAmountPlaceholder = "Enter amount",
|
|
8799
8803
|
customAmountLabel = "Custom Amount",
|
|
8800
8804
|
currencySymbol = "\u20B9",
|
|
8805
|
+
taxAmount: taxAmountProp,
|
|
8806
|
+
taxCalculator,
|
|
8807
|
+
taxLabel = "Taxes (GST)",
|
|
8808
|
+
rechargeAmountLabel = "Recharge amount",
|
|
8809
|
+
outstandingAmount,
|
|
8810
|
+
outstandingLabel = "Outstanding",
|
|
8811
|
+
topupLabel = "Top-up",
|
|
8801
8812
|
showVoucherLink = true,
|
|
8802
8813
|
voucherLinkText = "Have an offline code or voucher?",
|
|
8803
8814
|
voucherIcon = <Ticket className="size-4" />,
|
|
@@ -8894,6 +8905,10 @@ export const WalletTopup = React.forwardRef<HTMLDivElement, WalletTopupProps>(
|
|
|
8894
8905
|
};
|
|
8895
8906
|
|
|
8896
8907
|
const normalizedAmounts = amounts.map(normalizeAmountOption);
|
|
8908
|
+
const displayAmounts =
|
|
8909
|
+
outstandingAmount && outstandingAmount > 0
|
|
8910
|
+
? [{ value: 0 } as AmountOption, ...normalizedAmounts]
|
|
8911
|
+
: normalizedAmounts;
|
|
8897
8912
|
|
|
8898
8913
|
const handleAmountSelect = (value: number) => {
|
|
8899
8914
|
const newValue = selectedValue === value ? null : value;
|
|
@@ -8925,19 +8940,39 @@ export const WalletTopup = React.forwardRef<HTMLDivElement, WalletTopupProps>(
|
|
|
8925
8940
|
};
|
|
8926
8941
|
|
|
8927
8942
|
// Determine the effective pay amount
|
|
8928
|
-
const
|
|
8929
|
-
selectedValue ?? (customValue ? Number(customValue) :
|
|
8943
|
+
const baseSelection =
|
|
8944
|
+
selectedValue ?? (customValue ? Number(customValue) : null);
|
|
8945
|
+
|
|
8946
|
+
// Effective recharge amount (includes outstanding if present)
|
|
8947
|
+
const effectiveRechargeAmount =
|
|
8948
|
+
baseSelection !== null
|
|
8949
|
+
? outstandingAmount
|
|
8950
|
+
? outstandingAmount + baseSelection
|
|
8951
|
+
: baseSelection
|
|
8952
|
+
: 0;
|
|
8953
|
+
|
|
8954
|
+
// Tax computation
|
|
8955
|
+
const hasTax = taxCalculator !== undefined || taxAmountProp !== undefined;
|
|
8956
|
+
const computedTax =
|
|
8957
|
+
effectiveRechargeAmount > 0
|
|
8958
|
+
? taxCalculator
|
|
8959
|
+
? taxCalculator(effectiveRechargeAmount)
|
|
8960
|
+
: (taxAmountProp ?? 0)
|
|
8961
|
+
: 0;
|
|
8962
|
+
|
|
8963
|
+
// Total payable (recharge + tax)
|
|
8964
|
+
const totalPayable = effectiveRechargeAmount + computedTax;
|
|
8930
8965
|
|
|
8931
8966
|
const handlePay = () => {
|
|
8932
|
-
if (
|
|
8933
|
-
onPay?.(
|
|
8967
|
+
if (totalPayable > 0) {
|
|
8968
|
+
onPay?.(totalPayable);
|
|
8934
8969
|
}
|
|
8935
8970
|
};
|
|
8936
8971
|
|
|
8937
8972
|
const buttonText =
|
|
8938
8973
|
ctaText ||
|
|
8939
|
-
(
|
|
8940
|
-
? \`Pay \${formatCurrency(
|
|
8974
|
+
(totalPayable > 0
|
|
8975
|
+
? \`Pay \${formatCurrency(totalPayable, currencySymbol)} now\`
|
|
8941
8976
|
: "Select an amount");
|
|
8942
8977
|
|
|
8943
8978
|
return (
|
|
@@ -8974,8 +9009,15 @@ export const WalletTopup = React.forwardRef<HTMLDivElement, WalletTopupProps>(
|
|
|
8974
9009
|
{amountSectionLabel}
|
|
8975
9010
|
</label>
|
|
8976
9011
|
<div className="grid grid-cols-2 gap-4">
|
|
8977
|
-
{
|
|
9012
|
+
{displayAmounts.map((option) => {
|
|
8978
9013
|
const isSelected = selectedValue === option.value;
|
|
9014
|
+
const hasOutstanding =
|
|
9015
|
+
outstandingAmount !== undefined &&
|
|
9016
|
+
outstandingAmount > 0;
|
|
9017
|
+
const totalForOption = hasOutstanding
|
|
9018
|
+
? outstandingAmount + option.value
|
|
9019
|
+
: option.value;
|
|
9020
|
+
|
|
8979
9021
|
return (
|
|
8980
9022
|
<button
|
|
8981
9023
|
key={option.value}
|
|
@@ -8984,18 +9026,53 @@ export const WalletTopup = React.forwardRef<HTMLDivElement, WalletTopupProps>(
|
|
|
8984
9026
|
aria-checked={isSelected}
|
|
8985
9027
|
onClick={() => handleAmountSelect(option.value)}
|
|
8986
9028
|
className={cn(
|
|
8987
|
-
"flex
|
|
9029
|
+
"flex px-4 rounded text-sm transition-all cursor-pointer",
|
|
9030
|
+
hasOutstanding
|
|
9031
|
+
? "flex-col items-start gap-0.5 h-auto py-3"
|
|
9032
|
+
: "items-center h-10 py-2.5",
|
|
8988
9033
|
isSelected
|
|
8989
|
-
? "border border-semantic-
|
|
9034
|
+
? "border border-[var(--semantic-brand)] shadow-sm"
|
|
8990
9035
|
: "border border-semantic-border-input hover:border-semantic-text-muted"
|
|
8991
9036
|
)}
|
|
8992
9037
|
>
|
|
8993
|
-
<span
|
|
8994
|
-
{
|
|
8995
|
-
|
|
9038
|
+
<span
|
|
9039
|
+
className={cn(
|
|
9040
|
+
isSelected
|
|
9041
|
+
? "text-semantic-primary"
|
|
9042
|
+
: "text-semantic-text-primary",
|
|
9043
|
+
hasOutstanding && "font-medium"
|
|
9044
|
+
)}
|
|
9045
|
+
>
|
|
9046
|
+
{hasOutstanding
|
|
9047
|
+
? formatCurrency(
|
|
9048
|
+
totalForOption,
|
|
9049
|
+
currencySymbol
|
|
9050
|
+
)
|
|
9051
|
+
: option.label ||
|
|
9052
|
+
formatCurrency(
|
|
9053
|
+
option.value,
|
|
9054
|
+
currencySymbol
|
|
9055
|
+
)}
|
|
8996
9056
|
</span>
|
|
8997
|
-
{
|
|
8998
|
-
|
|
9057
|
+
{hasOutstanding && (
|
|
9058
|
+
<>
|
|
9059
|
+
<span className="text-xs text-semantic-text-muted">
|
|
9060
|
+
{outstandingLabel}:{" "}
|
|
9061
|
+
{formatCurrency(
|
|
9062
|
+
outstandingAmount,
|
|
9063
|
+
currencySymbol
|
|
9064
|
+
)}
|
|
9065
|
+
</span>
|
|
9066
|
+
<span className="text-xs text-semantic-text-muted">
|
|
9067
|
+
{topupLabel}:{" "}
|
|
9068
|
+
{option.value > 0
|
|
9069
|
+
? formatCurrency(
|
|
9070
|
+
option.value,
|
|
9071
|
+
currencySymbol
|
|
9072
|
+
)
|
|
9073
|
+
: "-"}
|
|
9074
|
+
</span>
|
|
9075
|
+
</>
|
|
8999
9076
|
)}
|
|
9000
9077
|
</button>
|
|
9001
9078
|
);
|
|
@@ -9016,6 +9093,31 @@ export const WalletTopup = React.forwardRef<HTMLDivElement, WalletTopupProps>(
|
|
|
9016
9093
|
/>
|
|
9017
9094
|
</div>
|
|
9018
9095
|
|
|
9096
|
+
{/* Recharge Summary */}
|
|
9097
|
+
{hasTax && effectiveRechargeAmount > 0 && (
|
|
9098
|
+
<div className="flex flex-col gap-2 rounded-lg bg-[var(--semantic-warning-surface)] px-4 py-3">
|
|
9099
|
+
<div className="flex items-center justify-between text-sm">
|
|
9100
|
+
<span className="text-semantic-text-primary">
|
|
9101
|
+
{rechargeAmountLabel}
|
|
9102
|
+
</span>
|
|
9103
|
+
<span className="text-semantic-text-primary font-medium">
|
|
9104
|
+
{formatCurrency(
|
|
9105
|
+
effectiveRechargeAmount,
|
|
9106
|
+
currencySymbol
|
|
9107
|
+
)}
|
|
9108
|
+
</span>
|
|
9109
|
+
</div>
|
|
9110
|
+
<div className="flex items-center justify-between text-sm">
|
|
9111
|
+
<span className="text-semantic-text-muted">
|
|
9112
|
+
{taxLabel}
|
|
9113
|
+
</span>
|
|
9114
|
+
<span className="text-semantic-text-muted">
|
|
9115
|
+
{formatCurrency(computedTax, currencySymbol)}
|
|
9116
|
+
</span>
|
|
9117
|
+
</div>
|
|
9118
|
+
</div>
|
|
9119
|
+
)}
|
|
9120
|
+
|
|
9019
9121
|
{/* Voucher Link or Voucher Code Input */}
|
|
9020
9122
|
{showVoucherLink && !showVoucherInput && (
|
|
9021
9123
|
<button
|
|
@@ -9067,7 +9169,7 @@ export const WalletTopup = React.forwardRef<HTMLDivElement, WalletTopupProps>(
|
|
|
9067
9169
|
className="w-full"
|
|
9068
9170
|
onClick={handlePay}
|
|
9069
9171
|
loading={loading}
|
|
9070
|
-
disabled={disabled ||
|
|
9172
|
+
disabled={disabled || totalPayable <= 0}
|
|
9071
9173
|
>
|
|
9072
9174
|
{buttonText}
|
|
9073
9175
|
</Button>
|
|
@@ -9136,6 +9238,24 @@ export interface WalletTopupProps {
|
|
|
9136
9238
|
/** Currency symbol (default: "\u20B9") */
|
|
9137
9239
|
currencySymbol?: string;
|
|
9138
9240
|
|
|
9241
|
+
// Tax / Summary
|
|
9242
|
+
/** Static tax amount to display in the summary section */
|
|
9243
|
+
taxAmount?: number;
|
|
9244
|
+
/** Function to dynamically compute tax from the recharge amount. Takes priority over taxAmount. */
|
|
9245
|
+
taxCalculator?: (amount: number) => number;
|
|
9246
|
+
/** Label for the tax line in the summary (default: "Taxes (GST)") */
|
|
9247
|
+
taxLabel?: string;
|
|
9248
|
+
/** Label for the recharge amount line in the summary (default: "Recharge amount") */
|
|
9249
|
+
rechargeAmountLabel?: string;
|
|
9250
|
+
|
|
9251
|
+
// Outstanding balance
|
|
9252
|
+
/** Outstanding balance. When set, auto-prepends an outstanding-only option and shows breakdowns in each amount button. */
|
|
9253
|
+
outstandingAmount?: number;
|
|
9254
|
+
/** Label for the outstanding breakdown in amount buttons (default: "Outstanding") */
|
|
9255
|
+
outstandingLabel?: string;
|
|
9256
|
+
/** Label for the topup breakdown in amount buttons (default: "Top-up") */
|
|
9257
|
+
topupLabel?: string;
|
|
9258
|
+
|
|
9139
9259
|
// Voucher link
|
|
9140
9260
|
/** Whether to show the voucher/code link */
|
|
9141
9261
|
showVoucherLink?: boolean;
|