This repository was archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathPistSignInSubscription.tsx
More file actions
115 lines (98 loc) · 4.21 KB
/
PistSignInSubscription.tsx
File metadata and controls
115 lines (98 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import type { FC, ChangeEvent, FocusEventHandler } from 'react'
import { SourcegraphLogo } from '@sourcegraph/branded/src/components/SourcegraphLogo'
import { H1, H2, Label, Form, useForm, useCheckboxes } from '@sourcegraph/wildcard'
import { LoaderButton } from '../components/LoaderButton'
import styles from './PostSignInSubscription.module.scss'
export const PostSignInSubscription: FC = props => {
const { formAPI, ref, handleSubmit } = useForm({
initialValues: { subscriptions: [] },
// eslint-disable-next-line no-console
onSubmit: values => console.log(values),
})
const {
input: { isChecked, onBlur, onChange },
} = useCheckboxes('subscriptions', formAPI)
return (
<div className={styles.root}>
<header className={styles.header}>
<SourcegraphLogo className={styles.logo} />
</header>
<section className={styles.content}>
<H1>Set your communication preferences</H1>
<Form ref={ref} className={styles.form} onSubmit={handleSubmit}>
<SubscriptionOption
value="product-updates"
title="Product updates"
message="Stay in the know on the latest awesome features"
isChecked={isChecked}
onBlur={onBlur}
onChange={onChange}
/>
<SubscriptionOption
value="tutorials"
title="Getting started tutorials"
message="Learn the nuts and bolts to become proficient in Sourcegraph tools"
isChecked={isChecked}
onBlur={onBlur}
onChange={onChange}
/>
<SubscriptionOption
value="security-updates"
title="Security updates"
message="Stay informed and help keep your environment secure"
isChecked={isChecked}
onBlur={onBlur}
onChange={onChange}
/>
<H2 className={styles.subHeading}>Help improve Sourcegraph</H2>
<SubscriptionOption
value="research-program"
title="Join our user research program"
message="Help us improve Sourcegraph for you and everyone!"
isChecked={isChecked}
onBlur={onBlur}
onChange={onChange}
/>
<footer className={styles.footer}>
<LoaderButton
type="submit"
alwaysShowLabel={true}
data-testid="insight-save-button"
loading={formAPI.submitting}
label={formAPI.submitting ? 'Submitting' : 'Next'}
disabled={formAPI.submitting}
variant="primary"
className={styles.submit}
/>
</footer>
</Form>
</section>
</div>
)
}
interface SubscriptionOptionProps {
value: string
title: string
message: string
isChecked: (value: string) => boolean
onChange?: (event: ChangeEvent<HTMLInputElement>) => void
onBlur?: FocusEventHandler<HTMLInputElement>
}
const SubscriptionOption: FC<SubscriptionOptionProps> = props => {
const { value, title, message, isChecked, onChange, onBlur } = props
return (
<Label className={styles.option}>
{/* eslint-disable-next-line react/forbid-elements */}
<input
type="checkbox"
value={value}
checked={isChecked(value)}
className={styles.optionCheckbox}
onBlur={onBlur}
onChange={onChange}
/>
<span className={styles.optionTitle}>{title}</span>
<span className={styles.optionMessage}>{message}</span>
</Label>
)
}