@@ -22,10 +22,12 @@ import { compute_cost } from "@cocalc/util/licenses/purchase/compute-cost";
22
22
import { DEFAULT_PURCHASE_INFO } from "@cocalc/util/licenses/purchase/student-pay" ;
23
23
import type { PurchaseInfo } from "@cocalc/util/licenses/purchase/types" ;
24
24
import { currency } from "@cocalc/util/misc" ;
25
+ import ShowError from "@cocalc/frontend/components/error" ;
25
26
26
27
export default function StudentPay ( { actions, settings } ) {
27
28
const intl = useIntl ( ) ;
28
29
30
+ const [ error , setError ] = useState < string > ( "" ) ;
29
31
const [ minPayment , setMinPayment ] = useState < number | undefined > ( undefined ) ;
30
32
const updateMinPayment = ( ) => {
31
33
( async ( ) => {
@@ -37,20 +39,24 @@ export default function StudentPay({ actions, settings }) {
37
39
} , [ ] ) ;
38
40
39
41
const [ info , setInfo ] = useState < PurchaseInfo > ( ( ) => {
40
- const cur = settings . get ( "payInfo" ) ?. toJS ( ) ;
42
+ let cur = settings . get ( "payInfo" ) ?. toJS ( ) ;
43
+ let info : PurchaseInfo ;
41
44
if ( cur != null ) {
42
- return cur ;
45
+ info = { ...DEFAULT_PURCHASE_INFO , ...cur } ;
46
+ } else {
47
+ info = {
48
+ ...DEFAULT_PURCHASE_INFO ,
49
+ // @ts -ignore
50
+ start : new Date ( ) ,
51
+ end : dayjs ( ) . add ( 3 , "month" ) . toDate ( ) ,
52
+ } ;
43
53
}
44
- const info = {
45
- ...DEFAULT_PURCHASE_INFO ,
46
- start : new Date ( ) ,
47
- end : dayjs ( ) . add ( 3 , "month" ) . toDate ( ) ,
48
- } as PurchaseInfo ;
49
54
setTimeout ( ( ) => {
50
55
// React requirement: this must happen in different render loop, because
51
56
// it causes an update to the UI.
52
57
actions . configuration . setStudentPay ( { info, cost } ) ;
53
58
} , 1 ) ;
59
+ console . log ( info ) ;
54
60
return info ;
55
61
} ) ;
56
62
@@ -74,7 +80,8 @@ export default function StudentPay({ actions, settings }) {
74
80
const cost = useMemo ( ( ) => {
75
81
try {
76
82
return compute_cost ( info ) . cost ;
77
- } catch ( _ ) {
83
+ } catch ( err ) {
84
+ setError ( `${ err } ` ) ;
78
85
return null ;
79
86
}
80
87
} , [ info ] ) ;
@@ -149,6 +156,7 @@ export default function StudentPay({ actions, settings }) {
149
156
</ >
150
157
}
151
158
>
159
+ < ShowError error = { error } setError = { setError } />
152
160
{ cost != null && ! showStudentPay && ! ! settings ?. get ( "student_pay" ) && (
153
161
< div style = { { float : "right" } } >
154
162
< MoneyStatistic title = "Cost Per Student" value = { cost } />
0 commit comments