oneslash-design-system 2.14.2 → 2.16.0
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/README.md +15 -0
- package/dist/DESIGN.md +138 -1
- package/dist/cases/accept-invite/signed-in.d.ts +1 -0
- package/dist/cases/accept-invite/signed-in.jsx +57 -0
- package/dist/cases/accept-invite/signed-out.d.ts +1 -0
- package/dist/cases/accept-invite/signed-out.jsx +33 -0
- package/dist/cases/accept-invite.md +161 -0
- package/dist/cases/agent-asks-before-risky-action.md +29 -0
- package/dist/cases/agent-cancels-when-unanswered.md +27 -0
- package/dist/cases/agent-refuses-clearly.md +31 -0
- package/dist/cases/agent-says-what-it-is.md +29 -0
- package/dist/cases/agent-shows-progress.md +30 -0
- package/dist/cases/agent-shows-sources.md +26 -0
- package/dist/cases/auth-gate-loading/spinner-with-line.d.ts +1 -0
- package/dist/cases/auth-gate-loading/spinner-with-line.jsx +10 -0
- package/dist/cases/auth-gate-loading/spinner.d.ts +1 -0
- package/dist/cases/auth-gate-loading/spinner.jsx +10 -0
- package/dist/cases/auth-gate-loading.md +70 -0
- package/dist/cases/check-your-email/alert-on-login.d.ts +1 -0
- package/dist/cases/check-your-email/alert-on-login.jsx +78 -0
- package/dist/cases/check-your-email/page.d.ts +1 -0
- package/dist/cases/check-your-email/page.jsx +49 -0
- package/dist/cases/check-your-email.md +184 -0
- package/dist/cases/confirm-destructive-action/inline.d.ts +1 -0
- package/dist/cases/confirm-destructive-action/inline.jsx +69 -0
- package/dist/cases/confirm-destructive-action/modal.d.ts +1 -0
- package/dist/cases/confirm-destructive-action/modal.jsx +66 -0
- package/dist/cases/confirm-destructive-action.md +211 -0
- package/dist/cases/confirm-dialogs.md +36 -0
- package/dist/cases/create-modal/quick.d.ts +1 -0
- package/dist/cases/create-modal/quick.jsx +80 -0
- package/dist/cases/create-modal/with-settings.d.ts +1 -0
- package/dist/cases/create-modal/with-settings.jsx +99 -0
- package/dist/cases/create-modal.md +244 -0
- package/dist/cases/device-login/popup.d.ts +1 -0
- package/dist/cases/device-login/popup.jsx +14 -0
- package/dist/cases/device-login/provider-first.d.ts +1 -0
- package/dist/cases/device-login/provider-first.jsx +98 -0
- package/dist/cases/device-login.md +171 -0
- package/dist/cases/email-confirmed/alert-on-login.d.ts +1 -0
- package/dist/cases/email-confirmed/alert-on-login.jsx +78 -0
- package/dist/cases/email-confirmed/page.d.ts +1 -0
- package/dist/cases/email-confirmed/page.jsx +21 -0
- package/dist/cases/email-confirmed.md +151 -0
- package/dist/cases/empty-list/region.d.ts +1 -0
- package/dist/cases/empty-list/region.jsx +13 -0
- package/dist/cases/empty-list/section.d.ts +1 -0
- package/dist/cases/empty-list/section.jsx +17 -0
- package/dist/cases/empty-list.md +77 -0
- package/dist/cases/empty-lists.md +35 -0
- package/dist/cases/empty-not-set-up/action.d.ts +1 -0
- package/dist/cases/empty-not-set-up/action.jsx +16 -0
- package/dist/cases/empty-not-set-up/pointer.d.ts +1 -0
- package/dist/cases/empty-not-set-up/pointer.jsx +13 -0
- package/dist/cases/empty-not-set-up.md +88 -0
- package/dist/cases/empty-search/clear-search.d.ts +1 -0
- package/dist/cases/empty-search/clear-search.jsx +29 -0
- package/dist/cases/empty-search.md +77 -0
- package/dist/cases/error-page/full-page.d.ts +1 -0
- package/dist/cases/error-page/full-page.jsx +19 -0
- package/dist/cases/error-page/in-shell.d.ts +1 -0
- package/dist/cases/error-page/in-shell.jsx +39 -0
- package/dist/cases/error-page.md +107 -0
- package/dist/cases/feedback-form/modal.d.ts +1 -0
- package/dist/cases/feedback-form/modal.jsx +89 -0
- package/dist/cases/feedback-form.md +139 -0
- package/dist/cases/forgot-password/in-place.d.ts +1 -0
- package/dist/cases/forgot-password/in-place.jsx +155 -0
- package/dist/cases/forgot-password/own-page.d.ts +1 -0
- package/dist/cases/forgot-password/own-page.jsx +99 -0
- package/dist/cases/forgot-password.md +328 -0
- package/dist/cases/form-errors.md +32 -0
- package/dist/cases/import-checklist/modal.d.ts +1 -0
- package/dist/cases/import-checklist/modal.jsx +125 -0
- package/dist/cases/import-checklist.md +188 -0
- package/dist/cases/inline-form-feedback/button-label.d.ts +1 -0
- package/dist/cases/inline-form-feedback/button-label.jsx +54 -0
- package/dist/cases/inline-form-feedback/inline-alert.d.ts +1 -0
- package/dist/cases/inline-form-feedback/inline-alert.jsx +49 -0
- package/dist/cases/inline-form-feedback/toast.d.ts +1 -0
- package/dist/cases/inline-form-feedback/toast.jsx +66 -0
- package/dist/cases/inline-form-feedback.md +237 -0
- package/dist/cases/invite-member/by-email.d.ts +1 -0
- package/dist/cases/invite-member/by-email.jsx +98 -0
- package/dist/cases/invite-member/by-link.d.ts +1 -0
- package/dist/cases/invite-member/by-link.jsx +122 -0
- package/dist/cases/invite-member.md +321 -0
- package/dist/cases/load-failure/inline.d.ts +1 -0
- package/dist/cases/load-failure/inline.jsx +52 -0
- package/dist/cases/load-failure/region.d.ts +1 -0
- package/dist/cases/load-failure/region.jsx +34 -0
- package/dist/cases/load-failure.md +155 -0
- package/dist/cases/log-out-confirm/modal.d.ts +1 -0
- package/dist/cases/log-out-confirm/modal.jsx +57 -0
- package/dist/cases/log-out-confirm.md +106 -0
- package/dist/cases/login-page/centered.d.ts +1 -0
- package/dist/cases/login-page/centered.jsx +72 -0
- package/dist/cases/login-page/email-only.d.ts +1 -0
- package/dist/cases/login-page/email-only.jsx +59 -0
- package/dist/cases/login-page/provider-first.d.ts +1 -0
- package/dist/cases/login-page/provider-first.jsx +66 -0
- package/dist/cases/login-page/split.d.ts +1 -0
- package/dist/cases/login-page/split.jsx +79 -0
- package/dist/cases/login-page.md +373 -0
- package/dist/cases/not-found-page/full-page.d.ts +1 -0
- package/dist/cases/not-found-page/full-page.jsx +16 -0
- package/dist/cases/not-found-page/in-shell.d.ts +1 -0
- package/dist/cases/not-found-page/in-shell.jsx +36 -0
- package/dist/cases/not-found-page.md +98 -0
- package/dist/cases/oauth-consent/simple.d.ts +1 -0
- package/dist/cases/oauth-consent/simple.jsx +73 -0
- package/dist/cases/oauth-consent/with-scope.d.ts +1 -0
- package/dist/cases/oauth-consent/with-scope.jsx +89 -0
- package/dist/cases/oauth-consent.md +233 -0
- package/dist/cases/rename/inline.d.ts +1 -0
- package/dist/cases/rename/inline.jsx +58 -0
- package/dist/cases/rename/modal.d.ts +1 -0
- package/dist/cases/rename/modal.jsx +70 -0
- package/dist/cases/rename.md +205 -0
- package/dist/cases/route-loading/full-screen.d.ts +1 -0
- package/dist/cases/route-loading/full-screen.jsx +8 -0
- package/dist/cases/route-loading/region.d.ts +1 -0
- package/dist/cases/route-loading/region.jsx +26 -0
- package/dist/cases/route-loading.md +84 -0
- package/dist/cases/set-new-password/form.d.ts +1 -0
- package/dist/cases/set-new-password/form.jsx +130 -0
- package/dist/cases/set-new-password/invalid-link.d.ts +1 -0
- package/dist/cases/set-new-password/invalid-link.jsx +50 -0
- package/dist/cases/set-new-password.md +247 -0
- package/dist/cases/sign-up-page/centered.d.ts +1 -0
- package/dist/cases/sign-up-page/centered.jsx +124 -0
- package/dist/cases/sign-up-page/provider-first.d.ts +1 -0
- package/dist/cases/sign-up-page/provider-first.jsx +124 -0
- package/dist/cases/sign-up-page/split.d.ts +1 -0
- package/dist/cases/sign-up-page/split.jsx +134 -0
- package/dist/cases/sign-up-page.md +478 -0
- package/dist/cases/success-feedback.md +35 -0
- package/dist/cases/type-to-confirm/inline.d.ts +1 -0
- package/dist/cases/type-to-confirm/inline.jsx +69 -0
- package/dist/cases/type-to-confirm/modal.d.ts +1 -0
- package/dist/cases/type-to-confirm/modal.jsx +73 -0
- package/dist/cases/type-to-confirm.md +222 -0
- package/dist/cases/unsaved-changes-guard/discard.d.ts +1 -0
- package/dist/cases/unsaved-changes-guard/discard.jsx +81 -0
- package/dist/cases/unsaved-changes-guard/save-or-discard.d.ts +1 -0
- package/dist/cases/unsaved-changes-guard/save-or-discard.jsx +85 -0
- package/dist/cases/unsaved-changes-guard.md +239 -0
- package/dist/cases/upgrade-prompt/inline.d.ts +1 -0
- package/dist/cases/upgrade-prompt/inline.jsx +52 -0
- package/dist/cases/upgrade-prompt/modal.d.ts +1 -0
- package/dist/cases/upgrade-prompt/modal.jsx +43 -0
- package/dist/cases/upgrade-prompt.md +174 -0
- package/dist/cases.json +2073 -0
- package/dist/components/alert.d.ts +3 -1
- package/dist/components/alert.jsx +6 -4
- package/dist/components/brandIcon.d.ts +12 -0
- package/dist/components/brandIcon.jsx +24 -0
- package/dist/components/emptyBox.d.ts +6 -1
- package/dist/components/emptyBox.jsx +4 -2
- package/dist/components/form.d.ts +11 -0
- package/dist/components/form.jsx +22 -0
- package/dist/components/heading.d.ts +2 -2
- package/dist/components/image.d.ts +14 -0
- package/dist/components/image.jsx +6 -0
- package/dist/components/layout.d.ts +18 -1
- package/dist/components/layout.jsx +16 -0
- package/dist/components/line.d.ts +3 -1
- package/dist/components/line.jsx +8 -1
- package/dist/components/loadingScreen.d.ts +5 -1
- package/dist/components/loadingScreen.jsx +4 -2
- package/dist/components/modal.d.ts +2 -1
- package/dist/components/modal.jsx +20 -8
- package/dist/components/radioGroup.d.ts +2 -1
- package/dist/components/radioGroup.jsx +2 -2
- package/dist/components/select.d.ts +2 -1
- package/dist/components/select.jsx +4 -2
- package/dist/components/tab.jsx +3 -2
- package/dist/components/tabsContainer.d.ts +4 -1
- package/dist/components/tabsContainer.jsx +11 -5
- package/dist/components/textField.d.ts +5 -1
- package/dist/components/textField.jsx +7 -3
- package/dist/components/toaster.d.ts +12 -0
- package/dist/components/toaster.jsx +103 -0
- package/dist/components/tooltip.jsx +3 -1
- package/dist/designTokens.d.ts +1 -0
- package/dist/designTokens.js +1 -0
- package/dist/internal/alert.d.ts +4 -0
- package/dist/internal/alert.js +6 -0
- package/dist/internal/modal.d.ts +2 -0
- package/dist/internal/modal.js +21 -0
- package/dist/internal/toaster.d.ts +19 -0
- package/dist/internal/toaster.js +50 -0
- package/dist/native-mapping.json +23 -1
- package/dist/stories/Alert.stories.d.ts +1 -0
- package/dist/stories/Alert.stories.jsx +16 -0
- package/dist/stories/BrandIcon.stories.d.ts +9 -0
- package/dist/stories/BrandIcon.stories.jsx +19 -0
- package/dist/stories/Cases.generated.stories.d.ts +60 -0
- package/dist/stories/Cases.generated.stories.jsx +116 -0
- package/dist/stories/EmptyBox.stories.d.ts +2 -0
- package/dist/stories/EmptyBox.stories.jsx +16 -0
- package/dist/stories/Form.stories.d.ts +6 -0
- package/dist/stories/Form.stories.jsx +26 -0
- package/dist/stories/Heading.stories.d.ts +6 -0
- package/dist/stories/Heading.stories.jsx +10 -0
- package/dist/stories/Image.stories.d.ts +7 -0
- package/dist/stories/Image.stories.jsx +18 -0
- package/dist/stories/Line.stories.d.ts +1 -0
- package/dist/stories/Line.stories.jsx +12 -0
- package/dist/stories/LoadingScreen.stories.d.ts +1 -0
- package/dist/stories/LoadingScreen.stories.jsx +8 -0
- package/dist/stories/Modal.stories.d.ts +2 -0
- package/dist/stories/Modal.stories.jsx +36 -0
- package/dist/stories/PageComponents.stories.d.ts +2 -0
- package/dist/stories/PageComponents.stories.jsx +15 -1
- package/dist/stories/RadioGroup.stories.d.ts +1 -0
- package/dist/stories/RadioGroup.stories.jsx +14 -0
- package/dist/stories/Select.stories.d.ts +1 -0
- package/dist/stories/Select.stories.jsx +14 -0
- package/dist/stories/TabsContainer.stories.d.ts +1 -0
- package/dist/stories/TabsContainer.stories.jsx +12 -0
- package/dist/stories/TextField.stories.d.ts +2 -0
- package/dist/stories/TextField.stories.jsx +22 -0
- package/dist/stories/Toaster.stories.d.ts +6 -0
- package/dist/stories/Toaster.stories.jsx +29 -0
- package/dist/tailwind-preset-auto.js +2 -1
- package/dist/tailwind-preset.js +2 -1
- package/dist/theme-auto.css +1 -0
- package/dist/theme.css +1 -0
- package/dist/tokens.css +1 -0
- package/dist/tokens.json +7 -0
- package/package.json +4 -2
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Error page
|
|
2
|
+
|
|
3
|
+
Something broke while showing a page, and the app cannot show it.
|
|
4
|
+
|
|
5
|
+
**Not built yet:** Scindo on the web shows the error's own message and its id. Commentify shows one line and 'Try again', with no heading and no way home. jinhwankim.com shows an `EmptyBox` with no Button.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Name the page in a `Heading` with `level={1}`: 'Something went wrong'.
|
|
10
|
+
- Say in one plain sentence what happened and what the person can do.
|
|
11
|
+
- Offer 'Try Again' first and 'Go Home' second.
|
|
12
|
+
- Keep the navigation when only one route failed.
|
|
13
|
+
|
|
14
|
+
## Don't
|
|
15
|
+
|
|
16
|
+
- Do not show the error's own message, a stack trace or an error id.
|
|
17
|
+
- Do not show a line of text with no way out.
|
|
18
|
+
- Do not hide the navigation when only one route failed.
|
|
19
|
+
|
|
20
|
+
## Option: Full page
|
|
21
|
+
|
|
22
|
+
Use when: The app shell itself failed, so nothing else can show.
|
|
23
|
+
|
|
24
|
+
Uses: `Button`, `Center`, `Cluster`, `Heading`, `Paragraph`, `Stack`
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
'use client';
|
|
28
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
29
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
30
|
+
import Button from 'oneslash-design-system/components/button';
|
|
31
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
32
|
+
|
|
33
|
+
// A real app passes the reset() its framework gives the error page, such as Next's error.tsx.
|
|
34
|
+
const reset = () => console.info('Render the page again');
|
|
35
|
+
|
|
36
|
+
export default function ErrorPageFullPage() {
|
|
37
|
+
return (
|
|
38
|
+
<Center fill>
|
|
39
|
+
<Stack gap="medium">
|
|
40
|
+
<Heading level={1} size="h5">Something went wrong</Heading>
|
|
41
|
+
<Paragraph tone="secondary" measure="none">Acme could not load. Try again, or go back to the home page.</Paragraph>
|
|
42
|
+
</Stack>
|
|
43
|
+
<Cluster>
|
|
44
|
+
<Button size="medium" type="primary" state="enabled" label="Try Again" onClickButton={reset} />
|
|
45
|
+
<Button size="medium" type="secondary" state="enabled" label="Go Home" href="/" />
|
|
46
|
+
</Cluster>
|
|
47
|
+
</Center>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Option: Inside the shell
|
|
53
|
+
|
|
54
|
+
Use when: One route failed and the navigation still works.
|
|
55
|
+
|
|
56
|
+
Uses: `Button`, `Cluster`, `Heading`, `Image`, `Paragraph`, `Stack`, `Surface`, `Tab`, `TabsContainer`
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
'use client';
|
|
60
|
+
import Image from 'oneslash-design-system/components/image';
|
|
61
|
+
import TabsContainer from 'oneslash-design-system/components/tabsContainer';
|
|
62
|
+
import Tab from 'oneslash-design-system/components/tab';
|
|
63
|
+
import Surface from 'oneslash-design-system/components/surface';
|
|
64
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
65
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
66
|
+
import Button from 'oneslash-design-system/components/button';
|
|
67
|
+
import { Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
68
|
+
|
|
69
|
+
// The product's mark. A real app passes its own file.
|
|
70
|
+
const productMark =
|
|
71
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E";
|
|
72
|
+
|
|
73
|
+
// A real app passes the router from its framework, such as Next's useRouter().
|
|
74
|
+
const router = { push: (url: string) => console.info(`Go to ${url}`) };
|
|
75
|
+
|
|
76
|
+
// A real app passes the reset() its framework gives the error page, such as Next's error.tsx.
|
|
77
|
+
const reset = () => console.info('Render the page again');
|
|
78
|
+
|
|
79
|
+
export default function ErrorPageInShell() {
|
|
80
|
+
return (
|
|
81
|
+
<Stack gap="large">
|
|
82
|
+
<Cluster gap="large">
|
|
83
|
+
<Image src={productMark} alt="Acme" width={32} height={32} />
|
|
84
|
+
<TabsContainer>
|
|
85
|
+
<Tab label="Home" isSelected={false} href="/" router={router} onClickTab={() => {}} />
|
|
86
|
+
<Tab label="Projects" isSelected href="/projects" router={router} onClickTab={() => {}} />
|
|
87
|
+
<Tab label="Settings" isSelected={false} href="/settings" router={router} onClickTab={() => {}} />
|
|
88
|
+
</TabsContainer>
|
|
89
|
+
</Cluster>
|
|
90
|
+
<Surface minHeight="tall" align="center">
|
|
91
|
+
<Stack gap="xlarge">
|
|
92
|
+
<Stack gap="medium">
|
|
93
|
+
<Heading level={1} size="h5">Something went wrong</Heading>
|
|
94
|
+
<Paragraph tone="secondary" measure="none">This page could not load. Try again, or go back to the home page.</Paragraph>
|
|
95
|
+
</Stack>
|
|
96
|
+
<Cluster>
|
|
97
|
+
<Button size="medium" type="primary" state="enabled" label="Try Again" onClickButton={reset} />
|
|
98
|
+
<Button size="medium" type="secondary" state="enabled" label="Go Home" href="/" />
|
|
99
|
+
</Cluster>
|
|
100
|
+
</Stack>
|
|
101
|
+
</Surface>
|
|
102
|
+
</Stack>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Seen in: Commentify, Scindo, jinhwankim.com.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function FeedbackFormModal(): import("react").JSX.Element;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import Toaster, { toast, dismissToast } from '../../components/toaster';
|
|
4
|
+
import Modal from '../../components/modal';
|
|
5
|
+
import Heading from '../../components/heading';
|
|
6
|
+
import Paragraph from '../../components/paragraph';
|
|
7
|
+
import Alert from '../../components/alert';
|
|
8
|
+
import Select from '../../components/select';
|
|
9
|
+
import Textarea from '../../components/textarea';
|
|
10
|
+
import Button from '../../components/button';
|
|
11
|
+
import { Center, Cluster, Stack } from '../../components/layout';
|
|
12
|
+
var categories = [
|
|
13
|
+
{ value: 'idea', label: 'An idea' },
|
|
14
|
+
{ value: 'bug', label: 'Something is broken' },
|
|
15
|
+
{ value: 'question', label: 'A question' },
|
|
16
|
+
{ value: 'other', label: 'Something else' },
|
|
17
|
+
];
|
|
18
|
+
export default function FeedbackFormModal() {
|
|
19
|
+
// Opens on the Modal, as if the person just chose Send Feedback.
|
|
20
|
+
var _a = useState(true), open = _a[0], setOpen = _a[1];
|
|
21
|
+
var _b = useState('idea'), category = _b[0], setCategory = _b[1];
|
|
22
|
+
var _c = useState('It would help to see who changed a task and when.'), message = _c[0], setMessage = _c[1];
|
|
23
|
+
var _d = useState(''), error = _d[0], setError = _d[1];
|
|
24
|
+
var _e = useState(false), sending = _e[0], setSending = _e[1];
|
|
25
|
+
var attempts = useRef(0);
|
|
26
|
+
var timer = useRef();
|
|
27
|
+
var toastIds = useRef([]);
|
|
28
|
+
// On unmount it stops the request and closes every toast it opened.
|
|
29
|
+
useEffect(function () { return function () {
|
|
30
|
+
clearTimeout(timer.current);
|
|
31
|
+
toastIds.current.forEach(function (id) { return dismissToast(id); });
|
|
32
|
+
toastIds.current = [];
|
|
33
|
+
}; }, []);
|
|
34
|
+
var text = message.trim();
|
|
35
|
+
function handleOpen() {
|
|
36
|
+
setError('');
|
|
37
|
+
setOpen(true);
|
|
38
|
+
}
|
|
39
|
+
// Escape, a click outside and Cancel all close it, except while the request runs.
|
|
40
|
+
function handleClose() {
|
|
41
|
+
if (sending)
|
|
42
|
+
return;
|
|
43
|
+
setOpen(false);
|
|
44
|
+
}
|
|
45
|
+
function handleSend() {
|
|
46
|
+
if (sending || text === '')
|
|
47
|
+
return;
|
|
48
|
+
setError('');
|
|
49
|
+
setSending(true);
|
|
50
|
+
attempts.current += 1;
|
|
51
|
+
// Stands in for the request to the server.
|
|
52
|
+
timer.current = setTimeout(function () {
|
|
53
|
+
setSending(false);
|
|
54
|
+
// The first try fails, to show the error. Send again and it works.
|
|
55
|
+
if (attempts.current === 1) {
|
|
56
|
+
setError('Your feedback was not sent. Check your connection and try again.');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setOpen(false);
|
|
60
|
+
setCategory('idea');
|
|
61
|
+
setMessage('');
|
|
62
|
+
toastIds.current.push(toast({ type: 'success', message: 'Feedback sent.' }));
|
|
63
|
+
}, 1200);
|
|
64
|
+
}
|
|
65
|
+
return (<Center width="page">
|
|
66
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
67
|
+
<Toaster />
|
|
68
|
+
<Stack gap="medium">
|
|
69
|
+
<Heading level={1} size="h5">Help</Heading>
|
|
70
|
+
<Paragraph tone="secondary" size="body2" measure="none">Guides, shortcuts and what is new in Acme.</Paragraph>
|
|
71
|
+
<Cluster>
|
|
72
|
+
<Button size="small" type="secondary" state="enabled" label="Send Feedback" decoIcon="MessageSquare" onClickButton={handleOpen}/>
|
|
73
|
+
</Cluster>
|
|
74
|
+
</Stack>
|
|
75
|
+
<Modal isOpen={open} size="small" initialFocus="body" title="Send Feedback" onClose={handleClose} actions={<>
|
|
76
|
+
<Button size="small" type="tertiary" state={sending ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleClose}/>
|
|
77
|
+
<Button size="small" type="primary" state={text === '' ? 'disabled' : 'enabled'} label="Send" loading={sending} onClickButton={handleSend}/>
|
|
78
|
+
</>}>
|
|
79
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={function () { return setError(''); }}/>}
|
|
80
|
+
<Stack gap="small">
|
|
81
|
+
{/* The line above names the field on screen, and `aria-label` names it for a screen reader. */}
|
|
82
|
+
<Paragraph tone="secondary" size="body2" measure="none">What is it about?</Paragraph>
|
|
83
|
+
<Select aria-label="What is it about?" value={category} options={categories} disabled={sending} onChange={function (v) { return setCategory(typeof v === 'string' ? v : v[0]); }}/>
|
|
84
|
+
</Stack>
|
|
85
|
+
{/* Cmd+Enter or Ctrl+Enter sends. Enter adds a new line. */}
|
|
86
|
+
<Textarea id="feedback-form-message" label="Your feedback" placeholder="What happened, or what would help?" value={message} disabled={sending} onSubmit={handleSend} onChange={function (e) { return setMessage(e.target.value); }}/>
|
|
87
|
+
</Modal>
|
|
88
|
+
</Center>);
|
|
89
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Feedback form
|
|
2
|
+
|
|
3
|
+
A person sends feedback about the product from inside it.
|
|
4
|
+
|
|
5
|
+
**Not built yet:** Scindo's feedback form labels the Button 'Sending...' while it runs, shows no error when sending fails, and replaces the form with a thank-you that closes after 1.5 seconds. It labels its fields with captions written by hand.
|
|
6
|
+
|
|
7
|
+
## Do
|
|
8
|
+
|
|
9
|
+
- Title the Modal 'Send Feedback' and label its action 'Send', after 'Cancel'.
|
|
10
|
+
- Ask for a category with a `Select` and the feedback with a `Textarea`. Start the category on a safe default.
|
|
11
|
+
- Put a line of text above the `Select` that says what it asks, and give the Select the same words as its `aria-label`.
|
|
12
|
+
- Focus the first field when the Modal opens, with `initialFocus="body"`.
|
|
13
|
+
- Disable the `Select` and the `Textarea` while it sends, and keep what the person wrote.
|
|
14
|
+
- Keep 'Send' `state="disabled"` while the feedback is empty.
|
|
15
|
+
- Send on Cmd+Enter or Ctrl+Enter from the `Textarea`, through its `onSubmit`. Enter adds a new line.
|
|
16
|
+
- Show an inline error Alert at the top of the Modal when sending fails, and keep what the person wrote.
|
|
17
|
+
- Close the Modal when it works, and show a toast: 'Feedback sent.'
|
|
18
|
+
|
|
19
|
+
## Don't
|
|
20
|
+
|
|
21
|
+
- Do not replace the form with a thank-you message that closes on its own.
|
|
22
|
+
- Do not change the label while it is loading, such as to 'Sending...'.
|
|
23
|
+
- Do not fail without a word. Say that the feedback was not sent.
|
|
24
|
+
- Do not clear what the person wrote when sending fails.
|
|
25
|
+
|
|
26
|
+
## Example: Send from a Modal
|
|
27
|
+
|
|
28
|
+
Uses: `Alert`, `Button`, `Center`, `Cluster`, `Heading`, `Modal`, `Paragraph`, `Select`, `Stack`, `Textarea`, `Toaster`, `dismissToast`, `toast`
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
'use client';
|
|
32
|
+
import { useEffect, useRef, useState } from 'react';
|
|
33
|
+
import Toaster, { toast, dismissToast } from 'oneslash-design-system/components/toaster';
|
|
34
|
+
import Modal from 'oneslash-design-system/components/modal';
|
|
35
|
+
import Heading from 'oneslash-design-system/components/heading';
|
|
36
|
+
import Paragraph from 'oneslash-design-system/components/paragraph';
|
|
37
|
+
import Alert from 'oneslash-design-system/components/alert';
|
|
38
|
+
import Select from 'oneslash-design-system/components/select';
|
|
39
|
+
import Textarea from 'oneslash-design-system/components/textarea';
|
|
40
|
+
import Button from 'oneslash-design-system/components/button';
|
|
41
|
+
import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
|
|
42
|
+
|
|
43
|
+
const categories = [
|
|
44
|
+
{ value: 'idea', label: 'An idea' },
|
|
45
|
+
{ value: 'bug', label: 'Something is broken' },
|
|
46
|
+
{ value: 'question', label: 'A question' },
|
|
47
|
+
{ value: 'other', label: 'Something else' },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export default function FeedbackFormModal() {
|
|
51
|
+
// Opens on the Modal, as if the person just chose Send Feedback.
|
|
52
|
+
const [open, setOpen] = useState(true);
|
|
53
|
+
const [category, setCategory] = useState('idea');
|
|
54
|
+
const [message, setMessage] = useState('It would help to see who changed a task and when.');
|
|
55
|
+
const [error, setError] = useState('');
|
|
56
|
+
const [sending, setSending] = useState(false);
|
|
57
|
+
const attempts = useRef(0);
|
|
58
|
+
const timer = useRef<ReturnType<typeof setTimeout>>();
|
|
59
|
+
const toastIds = useRef<string[]>([]);
|
|
60
|
+
|
|
61
|
+
// On unmount it stops the request and closes every toast it opened.
|
|
62
|
+
useEffect(() => () => {
|
|
63
|
+
clearTimeout(timer.current);
|
|
64
|
+
toastIds.current.forEach((id) => dismissToast(id));
|
|
65
|
+
toastIds.current = [];
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
const text = message.trim();
|
|
69
|
+
|
|
70
|
+
function handleOpen() {
|
|
71
|
+
setError('');
|
|
72
|
+
setOpen(true);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Escape, a click outside and Cancel all close it, except while the request runs.
|
|
76
|
+
function handleClose() {
|
|
77
|
+
if (sending) return;
|
|
78
|
+
setOpen(false);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function handleSend() {
|
|
82
|
+
if (sending || text === '') return;
|
|
83
|
+
setError('');
|
|
84
|
+
setSending(true);
|
|
85
|
+
attempts.current += 1;
|
|
86
|
+
// Stands in for the request to the server.
|
|
87
|
+
timer.current = setTimeout(() => {
|
|
88
|
+
setSending(false);
|
|
89
|
+
// The first try fails, to show the error. Send again and it works.
|
|
90
|
+
if (attempts.current === 1) {
|
|
91
|
+
setError('Your feedback was not sent. Check your connection and try again.');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
setOpen(false);
|
|
95
|
+
setCategory('idea');
|
|
96
|
+
setMessage('');
|
|
97
|
+
toastIds.current.push(toast({ type: 'success', message: 'Feedback sent.' }));
|
|
98
|
+
}, 1200);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<Center width="page">
|
|
103
|
+
{/* A real app mounts one Toaster near its root. */}
|
|
104
|
+
<Toaster />
|
|
105
|
+
<Stack gap="medium">
|
|
106
|
+
<Heading level={1} size="h5">Help</Heading>
|
|
107
|
+
<Paragraph tone="secondary" size="body2" measure="none">Guides, shortcuts and what is new in Acme.</Paragraph>
|
|
108
|
+
<Cluster>
|
|
109
|
+
<Button size="small" type="secondary" state="enabled" label="Send Feedback" decoIcon="MessageSquare" onClickButton={handleOpen} />
|
|
110
|
+
</Cluster>
|
|
111
|
+
</Stack>
|
|
112
|
+
<Modal
|
|
113
|
+
isOpen={open}
|
|
114
|
+
size="small"
|
|
115
|
+
initialFocus="body"
|
|
116
|
+
title="Send Feedback"
|
|
117
|
+
onClose={handleClose}
|
|
118
|
+
actions={
|
|
119
|
+
<>
|
|
120
|
+
<Button size="small" type="tertiary" state={sending ? 'disabled' : 'enabled'} label="Cancel" onClickButton={handleClose} />
|
|
121
|
+
<Button size="small" type="primary" state={text === '' ? 'disabled' : 'enabled'} label="Send" loading={sending} onClickButton={handleSend} />
|
|
122
|
+
</>
|
|
123
|
+
}
|
|
124
|
+
>
|
|
125
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={() => setError('')} />}
|
|
126
|
+
<Stack gap="small">
|
|
127
|
+
{/* The line above names the field on screen, and `aria-label` names it for a screen reader. */}
|
|
128
|
+
<Paragraph tone="secondary" size="body2" measure="none">What is it about?</Paragraph>
|
|
129
|
+
<Select aria-label="What is it about?" value={category} options={categories} disabled={sending} onChange={(v) => setCategory(typeof v === 'string' ? v : v[0])} />
|
|
130
|
+
</Stack>
|
|
131
|
+
{/* Cmd+Enter or Ctrl+Enter sends. Enter adds a new line. */}
|
|
132
|
+
<Textarea id="feedback-form-message" label="Your feedback" placeholder="What happened, or what would help?" value={message} disabled={sending} onSubmit={handleSend} onChange={(e) => setMessage(e.target.value)} />
|
|
133
|
+
</Modal>
|
|
134
|
+
</Center>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Seen in: Scindo.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ForgotPasswordInPlace(): import("react").JSX.Element;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Mail } from 'lucide-react';
|
|
4
|
+
import Image from '../../components/image';
|
|
5
|
+
import TabsContainer from '../../components/tabsContainer';
|
|
6
|
+
import Tab from '../../components/tab';
|
|
7
|
+
import Heading from '../../components/heading';
|
|
8
|
+
import Paragraph from '../../components/paragraph';
|
|
9
|
+
import Icon from '../../components/icon';
|
|
10
|
+
import Form from '../../components/form';
|
|
11
|
+
import Alert from '../../components/alert';
|
|
12
|
+
import TextField from '../../components/textField';
|
|
13
|
+
import Button from '../../components/button';
|
|
14
|
+
import Line from '../../components/line';
|
|
15
|
+
import BrandIcon from '../../components/brandIcon';
|
|
16
|
+
import { Center, Stack } from '../../components/layout';
|
|
17
|
+
// The product's mark. A real app passes its own file.
|
|
18
|
+
var productMark = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E";
|
|
19
|
+
// A real app passes the router from its framework, such as Next's useRouter().
|
|
20
|
+
var router = { push: function (url) { return console.info("Go to ".concat(url)); } };
|
|
21
|
+
// A small check: some text, an @, then some text.
|
|
22
|
+
function looksLikeEmail(value) {
|
|
23
|
+
return /^[^@\s]+@[^@\s]+$/.test(value);
|
|
24
|
+
}
|
|
25
|
+
export default function ForgotPasswordInPlace() {
|
|
26
|
+
// Opens on the reset form, as if the person typed their email on the login form and then chose 'Forgot Password?'.
|
|
27
|
+
var _a = useState('reset'), view = _a[0], setView = _a[1];
|
|
28
|
+
var _b = useState('ada@example.com'), email = _b[0], setEmail = _b[1];
|
|
29
|
+
var _c = useState(''), password = _c[0], setPassword = _c[1];
|
|
30
|
+
var _d = useState(''), error = _d[0], setError = _d[1];
|
|
31
|
+
var _e = useState(''), emailError = _e[0], setEmailError = _e[1];
|
|
32
|
+
var _f = useState(''), passwordError = _f[0], setPasswordError = _f[1];
|
|
33
|
+
var _g = useState(false), loading = _g[0], setLoading = _g[1];
|
|
34
|
+
var _h = useState(false), resending = _h[0], setResending = _h[1];
|
|
35
|
+
var _j = useState(false), resent = _j[0], setResent = _j[1];
|
|
36
|
+
var timer = useRef();
|
|
37
|
+
// Stops the request if the example goes away before it ends.
|
|
38
|
+
useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
|
|
39
|
+
// 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
if (!resent)
|
|
42
|
+
return;
|
|
43
|
+
var timer = setTimeout(function () { return setResent(false); }, 2000);
|
|
44
|
+
return function () { return clearTimeout(timer); };
|
|
45
|
+
}, [resent]);
|
|
46
|
+
// Moves between the login form, the reset form and the confirmation. The email stays as typed.
|
|
47
|
+
function showView(next) {
|
|
48
|
+
setError('');
|
|
49
|
+
setEmailError('');
|
|
50
|
+
setPasswordError('');
|
|
51
|
+
setView(next);
|
|
52
|
+
}
|
|
53
|
+
function handleLogIn() {
|
|
54
|
+
if (loading)
|
|
55
|
+
return;
|
|
56
|
+
setError('');
|
|
57
|
+
setEmailError('');
|
|
58
|
+
setPasswordError('');
|
|
59
|
+
if (!email.trim()) {
|
|
60
|
+
setEmailError('Enter your email.');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!looksLikeEmail(email.trim())) {
|
|
64
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!password) {
|
|
68
|
+
setPasswordError('Enter your password.');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
setLoading(true);
|
|
72
|
+
// Stands in for the request to the server.
|
|
73
|
+
timer.current = setTimeout(function () {
|
|
74
|
+
setLoading(false);
|
|
75
|
+
setError('That email and password do not match.');
|
|
76
|
+
}, 1200);
|
|
77
|
+
}
|
|
78
|
+
function handleSendLink() {
|
|
79
|
+
if (loading)
|
|
80
|
+
return;
|
|
81
|
+
setError('');
|
|
82
|
+
setEmailError('');
|
|
83
|
+
if (!email.trim()) {
|
|
84
|
+
setEmailError('Enter your email.');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!looksLikeEmail(email.trim())) {
|
|
88
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setLoading(true);
|
|
92
|
+
// Stands in for the request to the server.
|
|
93
|
+
// A failed request calls setError with one sentence instead, such as 'The link was not sent. Try again.'
|
|
94
|
+
timer.current = setTimeout(function () {
|
|
95
|
+
setLoading(false);
|
|
96
|
+
// Every address gets the same confirmation, so the page never says whether it has an account.
|
|
97
|
+
showView('sent');
|
|
98
|
+
}, 1200);
|
|
99
|
+
}
|
|
100
|
+
function handleSendAgain() {
|
|
101
|
+
// One click sends one email: clicks while it sends or reads 'Sent' do nothing.
|
|
102
|
+
if (resending || resent)
|
|
103
|
+
return;
|
|
104
|
+
setResending(true);
|
|
105
|
+
// Stands in for the request to the server.
|
|
106
|
+
timer.current = setTimeout(function () {
|
|
107
|
+
setResending(false);
|
|
108
|
+
setResent(true);
|
|
109
|
+
}, 1200);
|
|
110
|
+
}
|
|
111
|
+
if (view === 'sent') {
|
|
112
|
+
return (<Center fill>
|
|
113
|
+
<Icon icon={Mail} size="large" color="secondary"/>
|
|
114
|
+
<Stack gap="medium">
|
|
115
|
+
<Heading level={1} size="h5">Check your email</Heading>
|
|
116
|
+
<Paragraph tone="secondary" measure="none">If {email.trim()} has an Acme account, we sent it a link to reset the password.</Paragraph>
|
|
117
|
+
</Stack>
|
|
118
|
+
<Stack gap="large">
|
|
119
|
+
<Button size="medium" type="secondary" state="enabled" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain}/>
|
|
120
|
+
<Button size="medium" type="textOnly" state="enabled" label="Back to Login" onClickButton={function () { return showView('login'); }}/>
|
|
121
|
+
</Stack>
|
|
122
|
+
</Center>);
|
|
123
|
+
}
|
|
124
|
+
if (view === 'reset') {
|
|
125
|
+
return (<Center fill>
|
|
126
|
+
<Image src={productMark} alt="Acme" width={40} height={40}/>
|
|
127
|
+
<Stack gap="medium">
|
|
128
|
+
<Heading level={1} size="h5">Reset password</Heading>
|
|
129
|
+
<Paragraph tone="secondary" measure="none">Enter your email and we will send you a link to set a new password.</Paragraph>
|
|
130
|
+
</Stack>
|
|
131
|
+
<Form aria-label="Reset password" onSubmit={handleSendLink}>
|
|
132
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={function () { return setError(''); }}/>}
|
|
133
|
+
<TextField id="forgot-password-in-place-reset-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={function (e) { setEmail(e.target.value); setEmailError(''); }}/>
|
|
134
|
+
<Button size="medium" type="primary" state="enabled" label="Send Reset Link" htmlType="submit" loading={loading}/>
|
|
135
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Back to Login" onClickButton={function () { return showView('login'); }}/>
|
|
136
|
+
</Form>
|
|
137
|
+
</Center>);
|
|
138
|
+
}
|
|
139
|
+
return (<Center fill>
|
|
140
|
+
<Image src={productMark} alt="Acme" width={40} height={40}/>
|
|
141
|
+
<TabsContainer fill>
|
|
142
|
+
<Tab label="Log In" isSelected onClickTab={function () { }}/>
|
|
143
|
+
<Tab label="Sign Up" isSelected={false} href="/sign-up" router={router} onClickTab={function () { }}/>
|
|
144
|
+
</TabsContainer>
|
|
145
|
+
<Form aria-label="Log in" onSubmit={handleLogIn}>
|
|
146
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={function () { return setError(''); }}/>}
|
|
147
|
+
<TextField id="forgot-password-in-place-login-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={function (e) { setEmail(e.target.value); setEmailError(''); }}/>
|
|
148
|
+
<TextField id="forgot-password-in-place-login-password" label="Password" type="password" autoComplete="current-password" value={password} disabled={loading} error={Boolean(passwordError)} errorText={passwordError} onChange={function (e) { setPassword(e.target.value); setPasswordError(''); }}/>
|
|
149
|
+
<Button size="medium" type="primary" state="enabled" label="Log In" htmlType="submit" loading={loading}/>
|
|
150
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Forgot Password?" onClickButton={function () { return showView('reset'); }}/>
|
|
151
|
+
</Form>
|
|
152
|
+
<Line label="or"/>
|
|
153
|
+
<Button size="medium" type="secondary" state="enabled" label="Continue with Google" decoIcon={<BrandIcon name="google"/>}/>
|
|
154
|
+
</Center>);
|
|
155
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ForgotPasswordOwnPage(): import("react").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Mail } from 'lucide-react';
|
|
4
|
+
import Image from '../../components/image';
|
|
5
|
+
import Heading from '../../components/heading';
|
|
6
|
+
import Paragraph from '../../components/paragraph';
|
|
7
|
+
import Icon from '../../components/icon';
|
|
8
|
+
import Form from '../../components/form';
|
|
9
|
+
import Alert from '../../components/alert';
|
|
10
|
+
import TextField from '../../components/textField';
|
|
11
|
+
import Button from '../../components/button';
|
|
12
|
+
import { Center, Stack } from '../../components/layout';
|
|
13
|
+
// The product's mark. A real app passes its own file.
|
|
14
|
+
var productMark = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect width='40' height='40' rx='10' fill='%232f6b4f'/%3E%3Cpath d='M20 9 31 31h-6l-5-11-5 11H9z' fill='%23fff'/%3E%3C/svg%3E";
|
|
15
|
+
// A real app passes the router from its framework, such as Next's useRouter().
|
|
16
|
+
var router = { push: function (url) { return console.info("Go to ".concat(url)); } };
|
|
17
|
+
// A small check: some text, an @, then some text.
|
|
18
|
+
function looksLikeEmail(value) {
|
|
19
|
+
return /^[^@\s]+@[^@\s]+$/.test(value);
|
|
20
|
+
}
|
|
21
|
+
export default function ForgotPasswordOwnPage() {
|
|
22
|
+
var _a = useState(''), email = _a[0], setEmail = _a[1];
|
|
23
|
+
var _b = useState(''), sentTo = _b[0], setSentTo = _b[1];
|
|
24
|
+
var _c = useState(''), error = _c[0], setError = _c[1];
|
|
25
|
+
var _d = useState(''), emailError = _d[0], setEmailError = _d[1];
|
|
26
|
+
var _e = useState(false), loading = _e[0], setLoading = _e[1];
|
|
27
|
+
var _f = useState(false), resending = _f[0], setResending = _f[1];
|
|
28
|
+
var _g = useState(false), resent = _g[0], setResent = _g[1];
|
|
29
|
+
var timer = useRef();
|
|
30
|
+
// Stops the request if the example goes away before it ends.
|
|
31
|
+
useEffect(function () { return function () { return clearTimeout(timer.current); }; }, []);
|
|
32
|
+
// 'Sent' shows for 2 seconds, then the Button reads 'Send Again'.
|
|
33
|
+
useEffect(function () {
|
|
34
|
+
if (!resent)
|
|
35
|
+
return;
|
|
36
|
+
var timer = setTimeout(function () { return setResent(false); }, 2000);
|
|
37
|
+
return function () { return clearTimeout(timer); };
|
|
38
|
+
}, [resent]);
|
|
39
|
+
function handleSubmit() {
|
|
40
|
+
if (loading)
|
|
41
|
+
return;
|
|
42
|
+
setError('');
|
|
43
|
+
setEmailError('');
|
|
44
|
+
if (!email.trim()) {
|
|
45
|
+
setEmailError('Enter your email.');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (!looksLikeEmail(email.trim())) {
|
|
49
|
+
setEmailError('Enter an email address, like name@example.com.');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
setLoading(true);
|
|
53
|
+
var address = email.trim();
|
|
54
|
+
// Stands in for the request to the server.
|
|
55
|
+
// A failed request calls setError with one sentence instead, such as 'The link was not sent. Try again.'
|
|
56
|
+
timer.current = setTimeout(function () {
|
|
57
|
+
setLoading(false);
|
|
58
|
+
// Every address gets the same confirmation, so the page never says whether it has an account.
|
|
59
|
+
setSentTo(address);
|
|
60
|
+
}, 1200);
|
|
61
|
+
}
|
|
62
|
+
function handleSendAgain() {
|
|
63
|
+
// One click sends one email: clicks while it sends or reads 'Sent' do nothing.
|
|
64
|
+
if (resending || resent)
|
|
65
|
+
return;
|
|
66
|
+
setResending(true);
|
|
67
|
+
// Stands in for the request to the server.
|
|
68
|
+
timer.current = setTimeout(function () {
|
|
69
|
+
setResending(false);
|
|
70
|
+
setResent(true);
|
|
71
|
+
}, 1200);
|
|
72
|
+
}
|
|
73
|
+
if (sentTo) {
|
|
74
|
+
return (<Center fill>
|
|
75
|
+
<Icon icon={Mail} size="large" color="secondary"/>
|
|
76
|
+
<Stack gap="medium">
|
|
77
|
+
<Heading level={1} size="h5">Check your email</Heading>
|
|
78
|
+
<Paragraph tone="secondary" measure="none">If {sentTo} has an Acme account, we sent it a link to reset the password.</Paragraph>
|
|
79
|
+
</Stack>
|
|
80
|
+
<Stack gap="large">
|
|
81
|
+
<Button size="medium" type="secondary" state="enabled" label={resent ? 'Sent' : 'Send Again'} loading={resending} onClickButton={handleSendAgain}/>
|
|
82
|
+
<Button size="medium" type="textOnly" state="enabled" label="Back to Login" onClickButton={function () { return router.push('/login'); }}/>
|
|
83
|
+
</Stack>
|
|
84
|
+
</Center>);
|
|
85
|
+
}
|
|
86
|
+
return (<Center fill>
|
|
87
|
+
<Image src={productMark} alt="Acme" width={40} height={40}/>
|
|
88
|
+
<Stack gap="medium">
|
|
89
|
+
<Heading level={1} size="h5">Reset password</Heading>
|
|
90
|
+
<Paragraph tone="secondary" measure="none">Enter your email and we will send you a link to set a new password.</Paragraph>
|
|
91
|
+
</Stack>
|
|
92
|
+
<Form aria-label="Reset password" onSubmit={handleSubmit}>
|
|
93
|
+
{error && <Alert type="error" variant="inline" message={error} showCloseButton onClose={function () { return setError(''); }}/>}
|
|
94
|
+
<TextField id="forgot-password-own-page-email" label="Email" type="email" autoComplete="username" value={email} disabled={loading} error={Boolean(emailError)} errorText={emailError} onChange={function (e) { setEmail(e.target.value); setEmailError(''); }}/>
|
|
95
|
+
<Button size="medium" type="primary" state="enabled" label="Send Reset Link" htmlType="submit" loading={loading}/>
|
|
96
|
+
<Button size="medium" type="textOnly" state={loading ? 'disabled' : 'enabled'} label="Back to Login" onClickButton={function () { return router.push('/login'); }}/>
|
|
97
|
+
</Form>
|
|
98
|
+
</Center>);
|
|
99
|
+
}
|