-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update SharingSettings.tsx * fix * fix * fix
- Loading branch information
Showing
8 changed files
with
217 additions
and
53 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
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,38 @@ | ||
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'; | ||
|
||
export const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
root: { | ||
position: 'relative', | ||
maxHeight: 'fit-content', | ||
maxWidth: 508, | ||
background: '#FFFFFF', | ||
borderRadius: 10, | ||
padding: 40, | ||
boxShadow: '0px 2px 10px rgba(0, 0, 0, 0.05)', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: 24, | ||
'& .MuiFormControl-root': { | ||
marginBottom: 0, | ||
}, | ||
}, | ||
title: { | ||
fontSize: 18, | ||
fontWeight: 'bold', | ||
color: 'black', | ||
textAlign: 'center', | ||
}, | ||
subtitle: { | ||
fontSize: 14, | ||
fontWeight: 'normal', | ||
color: 'black', | ||
textAlign: 'center', | ||
}, | ||
actionWrapper: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
gap: 24, | ||
}, | ||
}), | ||
); |
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,122 @@ | ||
import { useState } from 'react'; | ||
import { useCookies } from 'react-cookie'; | ||
import { useNavigate } from 'react-router'; | ||
|
||
import { signIn } from 'next-auth/react'; | ||
import getConfig from 'next/config'; | ||
import { useRouter } from 'next/router'; | ||
|
||
import { Button, TextField, Typography } from '@material-ui/core'; | ||
|
||
import { useStyles } from './LoginByPAT.style'; | ||
|
||
import { COOKIE_INSTANCE_URL } from 'components/SelectServer'; | ||
import SelectServer from 'src/components/SelectServer'; | ||
import { useAlertHook } from 'src/hooks/use-alert.hook'; | ||
import { ServerListProps } from 'src/interfaces/server-list'; | ||
import i18n from 'src/locale'; | ||
|
||
type LoginByPATProps = { | ||
onNext: ( | ||
successCallback: () => void, | ||
failedCallback: () => void, | ||
email: string, | ||
) => Promise<void>; | ||
}; | ||
|
||
const LoginByPAT = ({ onNext }: LoginByPATProps) => { | ||
const styles = useStyles(); | ||
const router = useRouter(); | ||
const { publicRuntimeConfig } = getConfig(); | ||
const { showAlert } = useAlertHook(); | ||
const [cookies] = useCookies([COOKIE_INSTANCE_URL]); | ||
|
||
const [token, setToken] = useState(''); | ||
const [error] = useState({ | ||
isError: false, | ||
message: '', | ||
}); | ||
const [, setDisableSignIn] = useState<boolean>(false); | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const input = event.target.value; | ||
setToken(input); | ||
}; | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleNext = () => { | ||
signIn('tokenCredentials', { | ||
token, | ||
instanceURL: cookies[COOKIE_INSTANCE_URL], | ||
redirect: false, | ||
callbackUrl: publicRuntimeConfig.appAuthURL, | ||
}).then(response => { | ||
if (response.ok) { | ||
router.reload(); | ||
router.push('/'); | ||
} | ||
|
||
if (response.error) { | ||
showAlert({ | ||
message: token | ||
? i18n.t('Login.Alert.Invalid_OTP') | ||
: i18n.t('Login.Alert.Message'), | ||
severity: 'error', | ||
title: i18n.t('Login.Alert.Title'), | ||
}); | ||
setDisableSignIn(false); | ||
} | ||
}); | ||
}; | ||
|
||
const handleBack = () => { | ||
navigate('/'); | ||
}; | ||
|
||
const handleSwitchInstance = ( | ||
server: ServerListProps, | ||
callback?: () => void, | ||
) => { | ||
callback && callback(); | ||
}; | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<div> | ||
<Typography className={styles.title}> | ||
{i18n.t('Login.Email.LoginByEmail.Title')} | ||
</Typography> | ||
<Typography className={styles.subtitle}> | ||
{i18n.t('Login.Email.LoginByEmail.Subtitle')} | ||
</Typography> | ||
</div> | ||
<TextField | ||
fullWidth | ||
id="user-email-input" | ||
label="Token" | ||
variant="outlined" | ||
placeholder={i18n.t('Login.Email.LoginByEmail.Email_Placeholder')} | ||
value={token} | ||
onChange={handleChange} | ||
error={error.isError} | ||
helperText={error.isError ? error.message : ''} | ||
/> | ||
<SelectServer page="login" onSwitchInstance={handleSwitchInstance} /> | ||
<div className={styles.actionWrapper}> | ||
<Button variant="outlined" color="primary" onClick={handleBack}> | ||
{i18n.t('Login.Email.LoginByEmail.Back')} | ||
</Button> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
disabled={!token.length || error.isError} | ||
onClick={handleNext}> | ||
{i18n.t('Login.Email.LoginByEmail.Next')} | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoginByPAT; |
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
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,30 @@ | ||
import MyriadAPI from './base'; | ||
|
||
export const postToken = async ( | ||
hash: string, | ||
disguise: string, | ||
): Promise<void> => { | ||
try { | ||
await MyriadAPI().request({ | ||
url: `/user/personal-access-tokens`, | ||
method: 'POST', | ||
data: { | ||
token: disguise, | ||
hash: hash, | ||
}, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; | ||
|
||
export const getToken = async () => { | ||
try { | ||
await MyriadAPI().request({ | ||
url: `/user/personal-access-tokens`, | ||
method: 'GET', | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; |
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