Skip to content

Commit 81486b6

Browse files
committed
attempt to fix #8461
- I can't reproduce this in dev, so each attempt is just "make the code better and cross fingers"
1 parent c7f7d31 commit 81486b6

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

src/packages/next/components/store/add-box.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ Add a cash voucher to your shopping cart.
88
*/
99
import { useState, type JSX } from "react";
1010
import { Alert, Button, Spin } from "antd";
11-
1211
import { CostInputPeriod } from "@cocalc/util/licenses/purchase/types";
1312
import { round2up } from "@cocalc/util/misc";
1413
import { money } from "@cocalc/util/licenses/purchase/utils";
1514
import { addToCart } from "./add-to-cart";
1615
import { DisplayCost } from "./site-license-cost";
1716
import { periodicCost } from "@cocalc/util/licenses/purchase/compute-cost";
1817
import { decimalDivide } from "@cocalc/util/stripe/calc";
19-
18+
import ShowError from "@cocalc/frontend/components/error";
2019
import type { LicenseSource } from "@cocalc/util/upgrades/shopping";
2120

2221
export const ADD_STYLE = {
@@ -113,7 +112,11 @@ export function AddBox({
113112
router={router}
114113
setCartError={setCartError}
115114
/>
116-
{cartError && <Alert type="error" message={cartError} />}
115+
<ShowError
116+
error={cartError}
117+
setError={setCartError}
118+
style={{ marginTop: "5px" }}
119+
/>
117120
</div>
118121
);
119122
}
@@ -181,8 +184,8 @@ export function AddToCartButton({
181184
{clicked
182185
? "Moving to Cart..."
183186
: router.query.id != null
184-
? "Save Changes"
185-
: "Add to Cart"}
187+
? "Save Changes"
188+
: "Add to Cart"}
186189
{clicked && <Spin style={{ marginLeft: "15px" }} />}
187190
</Button>
188191
);

src/packages/next/components/store/usage-and-duration.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,17 @@ function getTimezoneFromDate(
4141
);
4242
}
4343

44-
export function UsageAndDuration(props: Props) {
45-
const {
46-
showExplanations = false,
47-
form,
48-
onChange,
49-
disabled = false,
50-
showUsage = true,
51-
discount = true,
52-
extraDuration,
53-
source,
54-
} = props;
55-
56-
//const duration: Duration = type === "license" ? "all" : "range";
57-
const duration = props.duration || "all";
58-
44+
export function UsageAndDuration({
45+
showExplanations = false,
46+
form,
47+
onChange,
48+
disabled = false,
49+
showUsage = true,
50+
discount = true,
51+
extraDuration,
52+
source,
53+
duration = "all",
54+
}: Props) {
5955
const profile = useProfile();
6056

6157
function renderUsageExplanation() {
@@ -138,17 +134,16 @@ export function UsageAndDuration(props: Props) {
138134

139135
function renderRangeSelector(getFieldValue) {
140136
const period = getFieldValue("period");
141-
if (period !== "range") {
142-
return;
143-
}
137+
138+
// ensure range is valid even if we aren't going to render this range selector visibly:
139+
// see https://github.com/sagemathinc/cocalc/issues/8461
144140
let range = getFieldValue("range");
145141
let invalidRange = range?.[0] == null || range?.[1] == null;
146142
if (invalidRange) {
147143
// Check if we're during initial load and URL has range parameters
148144
// If so, don't override with default dates
149145
const urlParams = new URLSearchParams(window.location.search);
150-
const hasRangeInUrl = urlParams.has('range');
151-
146+
const hasRangeInUrl = urlParams.has("range");
152147
if (!hasRangeInUrl) {
153148
const start = new Date();
154149
const dayMs = 1000 * 60 * 60 * 24;
@@ -159,6 +154,11 @@ export function UsageAndDuration(props: Props) {
159154
onChange();
160155
}
161156
}
157+
158+
if (period !== "range") {
159+
return;
160+
}
161+
162162
let suffix;
163163
try {
164164
if (!invalidRange) {
@@ -188,7 +188,9 @@ export function UsageAndDuration(props: Props) {
188188
extra={source === "course" ? renderDurationExplanation() : undefined}
189189
>
190190
<DateRange
191-
key={range ? `${range[0]?.getTime()}_${range[1]?.getTime()}` : 'no-range'}
191+
key={
192+
range ? `${range[0]?.getTime()}_${range[1]?.getTime()}` : "no-range"
193+
}
192194
disabled={disabled}
193195
noPast
194196
maxDaysInFuture={365 * 4}
@@ -287,8 +289,8 @@ export function UsageAndDuration(props: Props) {
287289
source === "course"
288290
? "range"
289291
: duration === "range"
290-
? "range"
291-
: "monthly";
292+
? "range"
293+
: "monthly";
292294

293295
switch (source) {
294296
case "course":

0 commit comments

Comments
 (0)