-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
569 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ReactNode, RefObject, useCallback, useRef, useState } from 'react'; | ||
import { useDebounce } from '../hooks/useDebounce'; | ||
|
||
type ConfirmPasswordMatchProps = { | ||
initialValue: boolean; | ||
children: ( | ||
match: boolean, | ||
doMatch: () => void, | ||
passRef: RefObject<HTMLInputElement>, | ||
confPassRef: RefObject<HTMLInputElement> | ||
) => ReactNode; | ||
}; | ||
export function ConfirmPasswordMatch({ initialValue, children }: ConfirmPasswordMatchProps) { | ||
const [match, setMatch] = useState(initialValue); | ||
const passRef = useRef<HTMLInputElement>(null); | ||
const confPassRef = useRef<HTMLInputElement>(null); | ||
|
||
const doMatch = useDebounce( | ||
useCallback(() => { | ||
const pass = passRef.current?.value; | ||
const confPass = confPassRef.current?.value; | ||
if (!confPass) { | ||
setMatch(initialValue); | ||
return; | ||
} | ||
setMatch(pass === confPass); | ||
}, [initialValue]), | ||
{ | ||
wait: 500, | ||
immediate: false, | ||
} | ||
); | ||
|
||
return children(match, doMatch, passRef, confPassRef); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { | ||
Overlay, | ||
OverlayBackdrop, | ||
Box, | ||
config, | ||
Text, | ||
TooltipProvider, | ||
Tooltip, | ||
Icons, | ||
Icon, | ||
Chip, | ||
IconButton, | ||
} from 'folds'; | ||
import FocusTrap from 'focus-trap-react'; | ||
|
||
export type UIAFlowOverlayProps = { | ||
currentStep: number; | ||
stepCount: number; | ||
children: ReactNode; | ||
onCancel: () => void; | ||
}; | ||
export function UIAFlowOverlay({ | ||
currentStep, | ||
stepCount, | ||
children, | ||
onCancel, | ||
}: UIAFlowOverlayProps) { | ||
return ( | ||
<Overlay open backdrop={<OverlayBackdrop />}> | ||
<FocusTrap focusTrapOptions={{ initialFocus: false }}> | ||
<Box style={{ height: '100%' }} direction="Column" grow="Yes" gap="400"> | ||
<Box grow="Yes" direction="Column" alignItems="Center" justifyContent="Center"> | ||
{children} | ||
</Box> | ||
<Box | ||
style={{ padding: config.space.S200 }} | ||
shrink="No" | ||
justifyContent="Center" | ||
alignItems="Center" | ||
gap="200" | ||
> | ||
<Chip as="div" radii="Pill" outlined> | ||
<Text as="span" size="T300">{`Step ${currentStep}/${stepCount}`}</Text> | ||
</Chip> | ||
<TooltipProvider | ||
tooltip={ | ||
<Tooltip variant="Critical"> | ||
<Text>Exit</Text> | ||
</Tooltip> | ||
} | ||
position="Top" | ||
> | ||
{(anchorRef) => ( | ||
<IconButton | ||
ref={anchorRef} | ||
variant="Critical" | ||
size="300" | ||
onClick={onCancel} | ||
radii="Pill" | ||
outlined | ||
> | ||
<Icon size="50" src={Icons.Cross} /> | ||
</IconButton> | ||
)} | ||
</TooltipProvider> | ||
</Box> | ||
</Box> | ||
</FocusTrap> | ||
</Overlay> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { IRequestTokenResponse } from 'matrix-js-sdk'; | ||
|
||
export type RequestEmailTokenResponse = { | ||
email: string; | ||
clientSecret: string; | ||
result: IRequestTokenResponse; | ||
}; | ||
export type RequestEmailTokenCallback = ( | ||
email: string, | ||
clientSecret: string, | ||
nextLink?: string | ||
) => Promise<RequestEmailTokenResponse>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { MatrixClient, MatrixError } from 'matrix-js-sdk'; | ||
import { useCallback, useRef } from 'react'; | ||
import { AsyncState, useAsyncCallback } from './useAsyncCallback'; | ||
import { RequestEmailTokenCallback, RequestEmailTokenResponse } from './types'; | ||
|
||
export const usePasswordEmail = ( | ||
mx: MatrixClient | ||
): [AsyncState<RequestEmailTokenResponse, MatrixError>, RequestEmailTokenCallback] => { | ||
const sendAttemptRef = useRef(1); | ||
|
||
const passwordEmailCallback: RequestEmailTokenCallback = useCallback( | ||
async (email, clientSecret, nextLink) => { | ||
const sendAttempt = sendAttemptRef.current; | ||
sendAttemptRef.current += 1; | ||
const result = await mx.requestPasswordEmailToken(email, clientSecret, sendAttempt, nextLink); | ||
return { | ||
email, | ||
clientSecret, | ||
result, | ||
}; | ||
}, | ||
[mx] | ||
); | ||
|
||
const [passwordEmailState, passwordEmail] = useAsyncCallback< | ||
RequestEmailTokenResponse, | ||
MatrixError, | ||
Parameters<RequestEmailTokenCallback> | ||
>(passwordEmailCallback); | ||
|
||
return [passwordEmailState, passwordEmail]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.