Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add last used indicator to the login page #1957

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -149,6 +149,7 @@ export const bn: Translation = {
authenticatorAppAdd: "সেট আপ করুন",
configured: "কনফিগার করা হয়েছে",
useAnotherMethod: "আরেকটি পদ্ধতি ব্যবহার করুন",
lastUsed: "সর্বশেষ ব্যবহৃত",
},
errors: {
somethingWentWrong:
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 @@ -155,6 +155,7 @@ export const de: Translation = {
authenticatorAppAdd: "Einrichten",
configured: "konfiguriert",
useAnotherMethod: "Eine andere Methode verwenden",
lastUsed: "Zuletzt verwendet",
},
errors: {
somethingWentWrong:
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 @@ -150,6 +150,7 @@ export const en: Translation = {
authenticatorAppAdd: "Set up",
configured: "configured",
useAnotherMethod: "Use another method",
lastUsed: "Last used",
},
errors: {
somethingWentWrong:
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 @@ -155,6 +155,7 @@ export const fr: Translation = {
authenticatorAppAdd: "Configurer",
configured: "configuré",
useAnotherMethod: "Utiliser une autre méthode",
lastUsed: "Dernière utilisation",
},
errors: {
somethingWentWrong:
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 @@ -151,6 +151,7 @@ export const it: Translation = {
authenticatorAppAdd: "Imposta",
configured: "configurato",
useAnotherMethod: "Usa un altro metodo",
lastUsed: "Ultimo utilizzo",
},
errors: {
somethingWentWrong: "Si è verificato un errore tecnico. Riprova più tardi.",
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 @@ -154,6 +154,7 @@ export const ptBR: Translation = {
authenticatorAppAdd: "Configurar",
configured: "configurado",
useAnotherMethod: "Usar outro método",
lastUsed: "Último uso",
},
errors: {
somethingWentWrong:
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 @@ -138,6 +138,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 @@ -146,6 +146,7 @@ export const zh: Translation = {
authenticatorAppAdd: "设置",
configured: "已配置",
useAnotherMethod: "使用其他方法",
lastUsed: "最后使用",
},
errors: {
somethingWentWrong: "发生技术错误。请稍后再试。",
Expand Down
15 changes: 14 additions & 1 deletion frontend/elements/src/pages/LoginInitPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const LoginInitPage = (props: Props) => {
setUIState,
stateHandler,
hidePasskeyButtonOnLogin,
lastLogin,
} = useContext(AppContext);

const [identifierType, setIdentifierType] = useState<IdentifierTypes>(null);
Expand Down Expand Up @@ -224,7 +225,14 @@ const LoginInitPage = (props: Props) => {
placeholder={t("labels.emailOrUsername")}
/>
)}
<Button uiAction={"email-submit"}>{t("labels.continue")}</Button>
<Button
uiAction={"email-submit"}
showLastUsed={["password", "passcode"].includes(
lastLogin?.login_method,
)}
>
{t("labels.continue")}
</Button>
</Form>
<Divider hidden={!showDivider}>{t("labels.or")}</Divider>
</Fragment>
Expand All @@ -240,6 +248,7 @@ const LoginInitPage = (props: Props) => {
}
disabled={!isWebAuthnSupported}
icon={"passkey"}
showLastUsed={lastLogin?.login_method == "passkey"}
>
{t("labels.signInPasskey")}
</Button>
Expand All @@ -258,6 +267,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
11 changes: 9 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,12 @@ 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"}
showLastUsed={lastLogin?.login_method == "passcode"}
>
{t("labels.passcode")}
</Button>
</Form>
Expand All @@ -75,6 +81,7 @@ const LoginMethodChooserPage = (props: Props) => {
secondary={true}
uiAction={"password-submit"}
icon={"password"}
showLastUsed={lastLogin?.login_method == "password"}
>
{t("labels.password")}
</Button>
Expand Down
Loading