bug double subscription
This commit is contained in:
@@ -101,8 +101,13 @@ export function ReportsPageClient({ initialYear }: { initialYear: number }) {
|
||||
[annual, ledger.data, period, selectedYear],
|
||||
);
|
||||
const subscriptionInsights = useMemo(
|
||||
() => getSubscriptionInsights(subscriptions.data ?? [], period),
|
||||
[period, subscriptions.data],
|
||||
() =>
|
||||
getSubscriptionInsights(
|
||||
subscriptions.data ?? [],
|
||||
subscriptionPayments.data ?? [],
|
||||
period,
|
||||
),
|
||||
[period, subscriptionPayments.data, subscriptions.data],
|
||||
);
|
||||
const billsInsights = useMemo(
|
||||
() => getBillsInsights(bills.data ?? [], period),
|
||||
|
||||
@@ -61,6 +61,7 @@ export function SubscriptionForm({
|
||||
const [subscriptionStatus, setSubscriptionStatus] = useState(
|
||||
editing?.subscriptionStatus ?? "active",
|
||||
);
|
||||
const [markPreviousAsPaid, setMarkPreviousAsPaid] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
@@ -76,6 +77,7 @@ export function SubscriptionForm({
|
||||
setCustomIntervalValue(String(editing?.customIntervalValue ?? ""));
|
||||
setCustomIntervalUnit(editing?.customIntervalUnit ?? "months");
|
||||
setSubscriptionStatus(editing?.subscriptionStatus ?? "active");
|
||||
setMarkPreviousAsPaid(false);
|
||||
setError("");
|
||||
}, [editing]);
|
||||
|
||||
@@ -96,6 +98,7 @@ export function SubscriptionForm({
|
||||
customIntervalValue: billingCycle === "custom" ? customIntervalValue : "",
|
||||
customIntervalUnit: billingCycle === "custom" ? customIntervalUnit : "",
|
||||
subscriptionStatus,
|
||||
markPreviousAsPaid: !editing && markPreviousAsPaid,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -193,6 +196,9 @@ export function SubscriptionForm({
|
||||
billingCycle={billingCycle}
|
||||
durationMode={durationMode}
|
||||
editing={editing}
|
||||
firstPaymentDate={firstPaymentDate}
|
||||
markPreviousAsPaid={markPreviousAsPaid}
|
||||
onMarkPreviousAsPaidChange={setMarkPreviousAsPaid}
|
||||
onStatusChange={setSubscriptionStatus}
|
||||
status={subscriptionStatus}
|
||||
title={title}
|
||||
@@ -439,6 +445,9 @@ function ReviewStep({
|
||||
billingCycle,
|
||||
durationMode,
|
||||
editing,
|
||||
firstPaymentDate,
|
||||
markPreviousAsPaid,
|
||||
onMarkPreviousAsPaidChange,
|
||||
status,
|
||||
onStatusChange,
|
||||
}: {
|
||||
@@ -447,6 +456,9 @@ function ReviewStep({
|
||||
billingCycle: BillingCycle;
|
||||
durationMode: DurationMode;
|
||||
editing?: Subscription;
|
||||
firstPaymentDate: string;
|
||||
markPreviousAsPaid: boolean;
|
||||
onMarkPreviousAsPaidChange: (value: boolean) => void;
|
||||
status: SubscriptionStatus;
|
||||
onStatusChange: (value: SubscriptionStatus) => void;
|
||||
}) {
|
||||
@@ -478,9 +490,32 @@ function ReviewStep({
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<p className="text-sm text-slate-400">
|
||||
Il nuovo abbonamento sarà creato come attivo.
|
||||
</p>
|
||||
<>
|
||||
<p className="text-sm text-slate-400">
|
||||
Il nuovo abbonamento sarà creato come attivo.
|
||||
</p>
|
||||
{firstPaymentDate < todayIso() ? (
|
||||
<label className="flex cursor-pointer items-start gap-3 rounded-lg border border-white/10 bg-slate-950/20 p-4 text-sm text-slate-200">
|
||||
<input
|
||||
checked={markPreviousAsPaid}
|
||||
className="mt-0.5 size-4 accent-sky-500"
|
||||
onChange={(event) =>
|
||||
onMarkPreviousAsPaidChange(event.target.checked)
|
||||
}
|
||||
type="checkbox"
|
||||
/>
|
||||
<span>
|
||||
<span className="block font-medium text-white">
|
||||
Segna le rate precedenti come pagate
|
||||
</span>
|
||||
<span className="mt-1 block text-xs leading-relaxed text-slate-400">
|
||||
Crea la cronologia dei rinnovi precedenti a oggi e li registra
|
||||
come pagati.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -89,6 +89,9 @@ export function SubscriptionsPageClient() {
|
||||
? list.map((item) => (item.$id === saved.$id ? saved : item))
|
||||
: [saved, ...list];
|
||||
});
|
||||
if (editing) {
|
||||
await subscriptionPayments.mutate();
|
||||
}
|
||||
setModalOpen(false);
|
||||
setEditing(undefined);
|
||||
notify("Abbonamento salvato");
|
||||
|
||||
Reference in New Issue
Block a user