-
Notifications
You must be signed in to change notification settings - Fork 5
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
4 changed files
with
88 additions
and
101 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 |
---|---|---|
@@ -1,90 +1,89 @@ | ||
import { ButtonsGroup } from '@codegouvfr/react-dsfr/ButtonsGroup' | ||
import { initButtonsLogin } from '@constants/connexion' | ||
import { loginFields } from '@constants/inputFields' | ||
import { useAuth } from 'react-oidc-context' | ||
import { | ||
type Dispatch, | ||
type SetStateAction, | ||
useCallback, | ||
useEffect, | ||
useState, | ||
} from 'react' | ||
import { LoginFields } from '../components/Auth/LoginFields' | ||
import { ButtonInformation } from '../components/Global/ButtonInformation' | ||
import { useNavigate } from 'react-router-dom' | ||
// import { ButtonsGroup } from '@codegouvfr/react-dsfr/ButtonsGroup' | ||
// import { initButtonsLogin } from '@constants/connexion' | ||
// import { loginFields } from '@constants/inputFields' | ||
// import { | ||
// type Dispatch, | ||
// type SetStateAction, | ||
// useCallback, | ||
// useEffect, | ||
// useState, | ||
// } from 'react' | ||
// import { LoginFields } from '../components/Auth/LoginFields' | ||
// import { ButtonInformation } from '../components/Global/ButtonInformation' | ||
// import { useNavigate } from 'react-router-dom' | ||
|
||
interface LoginProps { | ||
authFailed: boolean | ||
setAuthFailed: Dispatch<SetStateAction<boolean>> | ||
} | ||
// interface LoginProps { | ||
// authFailed: boolean | ||
// setAuthFailed: Dispatch<SetStateAction<boolean>> | ||
// } | ||
|
||
export function Login({ authFailed, setAuthFailed }: LoginProps) { | ||
const [isDisable, setIsDisable] = useState(true) | ||
const [password, setPassword] = useState('') | ||
const [id, setId] = useState('') | ||
const { login, isAuthenticated } = useAuth() | ||
const navigate = useNavigate() | ||
useEffect(() => { | ||
if (isAuthenticated) { | ||
navigate('/meeting', { replace: true }) | ||
} | ||
}, [isAuthenticated, navigate]) | ||
useEffect(() => { | ||
checkIfCompletedFields() | ||
}, [password, id]) | ||
// export function Login({ authFailed, setAuthFailed }: LoginProps) { | ||
// const [isDisable, setIsDisable] = useState(true) | ||
// const [password, setPassword] = useState('') | ||
// const [id, setId] = useState('') | ||
// // { login, isAuthenticated } = useAuth() | ||
// const navigate = useNavigate() | ||
// // useEffect(() => { | ||
// // if (isAuthenticated) { | ||
// // navigate('/meeting', { replace: true }) | ||
// // } | ||
// // }, [isAuthenticated, navigate]) | ||
// useEffect(() => { | ||
// checkIfCompletedFields() | ||
// }, [password, id]) | ||
|
||
const checkIfCompletedFields = useCallback(() => { | ||
setIsDisable(!(password.length && id.length)) | ||
}, [password, id]) | ||
// const checkIfCompletedFields = useCallback(() => { | ||
// setIsDisable(!(password.length && id.length)) | ||
// }, [password, id]) | ||
|
||
const handleChange = (e) => { | ||
e.preventDefault() | ||
if (e.target.name === 'username') { | ||
setId(e.target.value) | ||
} | ||
if (e.target.name === 'password') { | ||
setPassword(e.target.value) | ||
} | ||
} | ||
// const handleChange = (e) => { | ||
// e.preventDefault() | ||
// if (e.target.name === 'username') { | ||
// setId(e.target.value) | ||
// } | ||
// if (e.target.name === 'password') { | ||
// setPassword(e.target.value) | ||
// } | ||
// } | ||
|
||
const handleSubmit = async () => { | ||
setAuthFailed(false) | ||
try { | ||
const success = await login(id, password) | ||
if (!success) { | ||
setAuthFailed(true) | ||
} | ||
} catch (error) { | ||
setAuthFailed(true) | ||
} | ||
} | ||
// const handleSubmit = async () => { | ||
// setAuthFailed(false) | ||
// // try { | ||
// // const success = await login(id, password) | ||
// // if (!success) { | ||
// // setAuthFailed(true) | ||
// // } | ||
// // } catch (error) { | ||
// // setAuthFailed(true) | ||
// // } | ||
// // } | ||
|
||
return ( | ||
<div className="fr-container fr-mb-8w"> | ||
<div className="fr-grid-row"> | ||
<div className="fr-col fr-col-md-6"> | ||
<h1 className="fr-text-title--blue-france fr-mt-5w fr-mb-2w">Se connecter</h1> | ||
<p className="fr-mb-4w"> | ||
Ce service est à destination des France services participant à | ||
l'expérimentation Albert France services. | ||
</p> | ||
<LoginFields | ||
fields={loginFields} | ||
handleChange={handleChange} | ||
handleSubmit={handleSubmit} | ||
selectedValue={undefined} | ||
setSelectedValue={undefined} | ||
matricule={undefined} | ||
setMatricule={undefined} | ||
/> | ||
{authFailed && ( | ||
<ButtonInformation> | ||
Nom d'utilisateur ou mot de passe invalide. | ||
</ButtonInformation> | ||
)} | ||
<ButtonsGroup buttons={initButtonsLogin(handleSubmit, isDisable)} /> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
// return ( | ||
// <div className="fr-container fr-mb-8w"> | ||
// <div className="fr-grid-row"> | ||
// <div className="fr-col fr-col-md-6"> | ||
// <h1 className="fr-text-title--blue-france fr-mt-5w fr-mb-2w">Se connecter</h1> | ||
// <p className="fr-mb-4w"> | ||
// Ce service est à destination des France services participant à | ||
// l'expérimentation Albert France services. | ||
// </p> | ||
// <LoginFields | ||
// fields={loginFields} | ||
// handleChange={handleChange} | ||
// handleSubmit={handleSubmit} | ||
// selectedValue={undefined} | ||
// setSelectedValue={undefined} | ||
// matricule={undefined} | ||
// setMatricule={undefined} | ||
// /> | ||
// {authFailed && ( | ||
// <ButtonInformation> | ||
// Nom d'utilisateur ou mot de passe invalide. | ||
// </ButtonInformation> | ||
// )} | ||
// <ButtonsGroup buttons={initButtonsLogin(handleSubmit, isDisable)} /> | ||
// </div> | ||
// </div> | ||
// </div> | ||
// ) | ||
// } |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -23,7 +23,7 @@ export default () => { | |
}, | ||
host: true, | ||
strictPort: true, | ||
port: 4172, | ||
port: 4173, | ||
}, | ||
base: '/', | ||
}) | ||
|