-
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
12 changed files
with
307 additions
and
32 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,59 @@ | ||
import { Button, FormikField } from "@canonical/react-components"; | ||
import { Form, Formik } from "formik"; | ||
import { FC } from "react"; | ||
import { Outlet } from "react-router-dom"; | ||
import * as Yup from "yup"; | ||
import { AuthUser } from "types/auth-user"; | ||
|
||
type Props = { | ||
isAuthenticated?: boolean; | ||
setAuthUser: (user: AuthUser) => void; | ||
}; | ||
|
||
const schema = Yup.object().shape({ | ||
username: Yup.string().required("Required"), | ||
}); | ||
|
||
const Login: FC<Props> = ({ isAuthenticated, setAuthUser }) => { | ||
return isAuthenticated ? ( | ||
<Outlet /> | ||
) : ( | ||
<div className="p-login"> | ||
<div className="p-login__inner p-card--highlighted"> | ||
<div className="p-login__tagged-logo"> | ||
<span className="p-login__logo-container"> | ||
<div className="p-login__logo-tag"> | ||
<img | ||
className="p-login__logo-icon" | ||
src="https://assets.ubuntu.com/v1/82818827-CoF_white.svg" | ||
alt="" | ||
/> | ||
</div> | ||
<span className="p-login__logo-title">Identity platform</span> | ||
</span> | ||
</div> | ||
<Formik | ||
initialValues={{ username: "" }} | ||
onSubmit={({ username }) => { | ||
setAuthUser({ username, token: btoa(username) }); | ||
}} | ||
validationSchema={schema} | ||
> | ||
<Form> | ||
<FormikField | ||
label="Username" | ||
name="username" | ||
takeFocus | ||
type="text" | ||
/> | ||
<Button appearance="positive" type="submit"> | ||
Log in | ||
</Button> | ||
</Form> | ||
</Formik> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Login; |
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
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,78 @@ | ||
.p-login { | ||
align-items: center; | ||
background-color: rgb(255 255 255 / 75%); | ||
display: flex; | ||
height: 100vh; | ||
left: 0; | ||
place-content: center; | ||
position: fixed; | ||
top: 0; | ||
width: 100vw; | ||
z-index: 999; | ||
|
||
&__inner { | ||
width: 20rem; | ||
|
||
.p-button--positive { | ||
margin: 0 auto; | ||
width: 100%; | ||
} | ||
} | ||
|
||
// A modified version of the navigation logo: | ||
// https://github.com/canonical/vanilla-framework/blob/fe40c9d38febd159a280b8f70713e02598a3a3d2/scss/_patterns_navigation.scss#L314 | ||
.p-login__tagged-logo { | ||
display: flex; // to prevent logo link from expanding full width | ||
margin-right: 0; | ||
|
||
@media (min-width: $breakpoint-navigation-threshold) { | ||
min-width: 13rem; | ||
} | ||
|
||
.p-login__logo-tag { | ||
background-color: $color-ubuntu; | ||
height: $navigation-logo-tag-height; | ||
left: 0; | ||
position: absolute; | ||
top: 0; | ||
width: $navigation-logo-tag-width; | ||
|
||
@media (min-width: $breakpoint-navigation-threshold) { | ||
height: $navigation-logo-tag-height-desktop; | ||
} | ||
} | ||
|
||
.p-login__logo-icon { | ||
bottom: $spv-navigation-logo-bottom-position; | ||
height: $navigation-logo-size; | ||
left: 50%; | ||
position: absolute; | ||
transform: translate(-50%, 0); | ||
width: $navigation-logo-size; | ||
} | ||
|
||
.p-login__logo-title { | ||
color: $colors--theme--text-default; | ||
font-size: 1.3rem; | ||
font-weight: 300; | ||
line-height: $navigation-logo-size; | ||
} | ||
|
||
.p-login__logo-container { | ||
@extend %navigation-link; | ||
|
||
// within logo we don't need a regular item padding | ||
@extend %vf-reset-horizontal-padding; | ||
|
||
padding-left: $navigation-logo-padding; | ||
|
||
&:hover { | ||
background-color: transparent !important; | ||
} | ||
|
||
&::before { | ||
content: none; | ||
} | ||
} | ||
} | ||
} |
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,10 @@ | ||
.p-side-navigation--user-menu { | ||
bottom: 0; | ||
position: absolute; | ||
width: 100%; | ||
|
||
button { | ||
justify-content: left; | ||
width: 100%; | ||
} | ||
} |
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,4 @@ | ||
export type AuthUser = { | ||
username: string; | ||
token: string; | ||
}; |
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,36 @@ | ||
import { useState } from "react"; | ||
|
||
function useLocalStorage<V>( | ||
key: string, | ||
initialValue: V, | ||
): [V, (value: V) => void] { | ||
// State to store our value | ||
// Pass initial state function to useState so logic is only executed once | ||
const [storedValue, setStoredValue] = useState<V>(() => { | ||
try { | ||
const item = window.localStorage.getItem(key); | ||
return item ? JSON.parse(item) : initialValue; | ||
} catch (error) { | ||
// Not shown in UI. Logged for debugging purposes. | ||
console.error("Unable to parse local storage:", error); | ||
return initialValue; | ||
} | ||
}); | ||
|
||
// Return a wrapped version of useState's setter function that persists the | ||
// new value to localStorage. | ||
const setValue = (value: V) => { | ||
try { | ||
const stringified = JSON.stringify(value); | ||
setStoredValue(value); | ||
window.localStorage.setItem(key, stringified); | ||
} catch (error) { | ||
// Not shown in UI. Logged for debugging purposes. | ||
console.error(error); | ||
} | ||
}; | ||
|
||
return [storedValue, setValue]; | ||
} | ||
|
||
export default useLocalStorage; |
Oops, something went wrong.