apps/web: always show telegram bot link for ldap-tfa

This commit is contained in:
vchikalkin 2024-07-18 19:02:52 +03:00
parent 2d41e403ce
commit 4eaf62da0b
2 changed files with 6 additions and 3 deletions

View File

@ -11,7 +11,7 @@ const { TELEGRAM_BOT_URL } = publicRuntimeConfig;
export function BaseForm({ children, onSubmit }: FormProps & PropsWithChildren) {
const { handleSubmit, register } = useForm<FormData>();
const {
state: { error, step },
state: { error, step, tfa },
} = useContext(FormStateContext);
return (
@ -32,7 +32,7 @@ export function BaseForm({ children, onSubmit }: FormProps & PropsWithChildren)
autoComplete="on"
{...register('password', { required: true })}
/>
{step === 'telegram-login' ? (
{tfa ? (
<a target="_blank" className="info" href={TELEGRAM_BOT_URL} rel="noreferrer">
Открыть чат с ботом
</a>

View File

@ -6,6 +6,7 @@ import { createContext, useMemo, useReducer } from 'react';
type State = {
error: string | undefined;
step: 'login' | 'telegram' | 'telegram-login';
tfa: boolean;
user: LdapUser | undefined;
};
@ -59,13 +60,15 @@ type Context = {
export const FormStateContext = createContext<Context>({} as Context);
type FormStateProviderProps = {
readonly tfa: boolean;
readonly user?: LdapUser;
} & PropsWithChildren;
export function FormStateProvider({ children, user = undefined }: FormStateProviderProps) {
export function FormStateProvider({ children, tfa, user = undefined }: FormStateProviderProps) {
const [state, dispatch] = useReducer(reducer, {
error: undefined,
step: 'login',
tfa,
user,
});