Skip to content

Commit

Permalink
feat: add last used indicator to the login page (#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoern-m authored Nov 29, 2024
1 parent f32f48e commit aa97808
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 6 deletions.
8 changes: 7 additions & 1 deletion frontend/elements/src/components/form/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styles from "./styles.sass";
import LoadingSpinner from "../icons/LoadingSpinner";
import Icon, { IconName } from "../icons/Icon";
import { AppContext, UIAction } from "../../contexts/AppProvider";
import LastUsed from "./LastUsed";

type Props = {
uiAction?: UIAction;
Expand All @@ -19,6 +20,7 @@ type Props = {
isSuccess?: boolean;
disabled?: boolean;
autofocus?: boolean;
showLastUsed?: boolean;
onClick?: (event: Event) => void;
icon?: IconName;
};
Expand All @@ -30,6 +32,7 @@ const Button = ({
secondary,
dangerous,
autofocus,
showLastUsed,
onClick,
icon,
...props
Expand Down Expand Up @@ -93,7 +96,10 @@ const Button = ({
{icon ? (
<Icon name={icon} secondary={secondary} disabled={disabled} />
) : null}
{children}
<div className={styles.caption}>
<span>{children}</span>
{showLastUsed ? <LastUsed /> : null}
</div>
</LoadingSpinner>
</button>
);
Expand Down
11 changes: 11 additions & 0 deletions frontend/elements/src/components/form/LastUsed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import cx from "classnames";
import styles from "./styles.sass";
import { useContext } from "preact/compat";
import { TranslateContext } from "@denysvuika/preact-translate";

const LastUsed = () => {
const { t } = useContext(TranslateContext);
return <span className={cx(styles.lastUsed)}>{t("labels.lastUsed")}</span>;
};

export default LastUsed;
17 changes: 14 additions & 3 deletions frontend/elements/src/components/form/styles.sass
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
white-space: nowrap
width: 100%
min-width: variables.$button-min-width
height: variables.$item-height
min-height: variables.$item-height
outline: none
cursor: pointer
transition: 0.1s ease-out
Expand Down Expand Up @@ -68,7 +68,7 @@
color: variables.$color
background: variables.$background-color
border-color: variables.$color
justify-content: left
justify-content: flex-start

&.secondary:hover
color: variables.$color
Expand All @@ -92,8 +92,19 @@
flex-grow: 0
width: auto

// Input Styles
.caption
flex-grow: 1
flex-wrap: wrap
display: flex
justify-content: space-between
align-items: baseline

// Last Used Styles
.lastUsed
color: variables.$color-shade-1
font-size: smaller

// Input Styles
.inputWrapper
flex-grow: 1
position: relative
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/components/icons/styles.sass
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
height: 100%
margin: 0 5px
justify-content: inherit
flex-wrap: inherit

&.centerContent
justify-content: center
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/i18n/bn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const bn: Translation = {
authenticatorAppAdd: "সেট আপ করুন",
configured: "কনফিগার করা হয়েছে",
useAnotherMethod: "আরেকটি পদ্ধতি ব্যবহার করুন",
lastUsed: "সর্বশেষ ব্যবহৃত",
trustDevice: "এই ব্রাউজারটি বিশ্বাস করবেন",
staySignedIn: "সাইন ইন থাকা চালিয়ে যান",
},
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const de: Translation = {
authenticatorAppAdd: "Einrichten",
configured: "konfiguriert",
useAnotherMethod: "Eine andere Methode verwenden",
lastUsed: "Zuletzt verwendet",
trustDevice: "Diesem Browser vertrauen",
staySignedIn: "Angemeldet bleiben",
},
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const en: Translation = {
authenticatorAppAdd: "Set up",
configured: "configured",
useAnotherMethod: "Use another method",
lastUsed: "Last used",
trustDevice: "Trust this browser",
staySignedIn: "Stay signed in",
},
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/i18n/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const fr: Translation = {
authenticatorAppAdd: "Configurer",
configured: "configuré",
useAnotherMethod: "Utiliser une autre méthode",
lastUsed: "Dernière utilisation",
trustDevice: "Faire confiance à ce navigateur",
staySignedIn: "Rester connecté",
},
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/i18n/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const it: Translation = {
authenticatorAppAdd: "Imposta",
configured: "configurato",
useAnotherMethod: "Usa un altro metodo",
lastUsed: "Ultimo utilizzo",
trustDevice: "Fidarsi di questo browser",
staySignedIn: "Rimani connesso",
},
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/i18n/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const ptBR: Translation = {
authenticatorAppAdd: "Configurar",
configured: "configurado",
useAnotherMethod: "Usar outro método",
lastUsed: "Último uso",
trustDevice: "Confiar neste navegador",
staySignedIn: "Manter-me conectado",
},
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export interface Translation {
currentSession: string;
newSecurityKeyName: string;
createSecurityKey: string;
lastUsed: string;
};
errors: {
somethingWentWrong: string;
Expand Down
1 change: 1 addition & 0 deletions frontend/elements/src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const zh: Translation = {
authenticatorAppAdd: "设置",
configured: "已配置",
useAnotherMethod: "使用其他方法",
lastUsed: "最后使用",
trustDevice: "信任此浏览器",
staySignedIn: "保持登录状态",
},
Expand Down
5 changes: 5 additions & 0 deletions frontend/elements/src/pages/LoginInitPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const LoginInitPage = (props: Props) => {
setUIState,
stateHandler,
hidePasskeyButtonOnLogin,
lastLogin,
} = useContext(AppContext);

const [identifierType, setIdentifierType] = useState<IdentifierTypes>(null);
Expand Down Expand Up @@ -269,6 +270,10 @@ const LoginInitPage = (props: Props) => {
secondary
// @ts-ignore
icon={v.value}
showLastUsed={
lastLogin?.login_method == "third_party" &&
lastLogin?.third_party_provider == v.value
}
>
{t("labels.signInWith", { provider: v.name })}
</Button>
Expand Down
9 changes: 7 additions & 2 deletions frontend/elements/src/pages/LoginMethodChooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ interface Props {

const LoginMethodChooserPage = (props: Props) => {
const { t } = useContext(TranslateContext);
const { hanko, setLoadingAction, stateHandler } = useContext(AppContext);
const { hanko, setLoadingAction, stateHandler, lastLogin } =
useContext(AppContext);
const { flowState } = useFlowState(props.state);

const onPasswordSelectSubmit = async (event: Event) => {
Expand Down Expand Up @@ -63,7 +64,11 @@ const LoginMethodChooserPage = (props: Props) => {
hidden={!flowState.actions.continue_to_passcode_confirmation?.(null)}
onSubmit={onPasscodeSelectSubmit}
>
<Button secondary={true} uiAction={"passcode-submit"} icon={"mail"}>
<Button
secondary={true}
uiAction={"passcode-submit"}
icon={"mail"}
>
{t("labels.passcode")}
</Button>
</Form>
Expand Down

0 comments on commit aa97808

Please sign in to comment.