Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,23 @@
*/

.set-password-form__text-input--label {
font-weight: var(--mantine-font-weight-bold);
font-weight: 500;
margin-bottom: 4px;
}

.set-password-form__text-input {
transition: border-color 0.2s ease;
}

.set-password-form__text-input:focus {
border-color: var(--mantine-color-blue-6);
}

.set-password-form__submit-button {
margin-top: 16px;
transition: background-color 0.2s ease;
}

.set-password-form__submit-button:hover {
background-color: var(--mantine-color-blue-7);
}
67 changes: 51 additions & 16 deletions packages/lib/src/components/SetPassword/SetPasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,31 @@ import {
SetPasswordFormType,
SetPasswordInput,
} from '@frachtwerk/essencium-types'
import { Button, Stack } from '@mantine/core'
import { Button, Stack, Text } from '@mantine/core'
import { useTranslation } from 'next-i18next'
import type { JSX } from 'react'
import { type ChangeEvent, type JSX, useState } from 'react'

import { useZodForm } from '../../hooks'
import { ControlledPasswordInput } from '../Form'
import { PasswordStrengthIndicator } from '../PasswordStrengthIndicator/PasswordStrengthIndicator'
import classes from './SetPasswordForm.module.css'

type Props = {
handleSetPassword: (password: SetPasswordInput['password']) => void
isAdmin?: boolean
}

export function SetPasswordForm({ handleSetPassword }: Props): JSX.Element {
/**
* SetPasswordForm component for handling password setting and validation
* @param handleSetPassword - Callback function to handle password submission
* @param isAdmin - Optional flag to indicate if the user is an admin (affects password requirements)
*/
export function SetPasswordForm({ handleSetPassword, isAdmin }: Props): JSX.Element {
const { t } = useTranslation()
const [passwordValue, setPasswordValue] = useState<string | null>(null)
const [isPasswordFocused, setIsPasswordFocused] = useState(false)

const { handleSubmit, control } = useZodForm({
const { handleSubmit, control, formState: { errors } } = useZodForm({
schema: setPasswordFormSchema,
})

Expand All @@ -49,30 +58,56 @@ export function SetPasswordForm({ handleSetPassword }: Props): JSX.Element {

return (
<form onSubmit={handleSubmit(onSubmit)}>
<Stack>
<ControlledPasswordInput
name="password"
control={control}
placeholder={String(t('setPasswordView.form.newPassword'))}
label={t('setPasswordView.form.newPassword')}
withAsterisk
classNames={{
label: classes['set-password-form__text-input--label'],
}}
/>
<Stack gap="md">
<PasswordStrengthIndicator
passwordValue={passwordValue}
isAdmin={isAdmin}
offset={5}
position="bottom-start"
width={300}
opened={isPasswordFocused}
>
<ControlledPasswordInput
name="password"
control={control}
onChange={(event: ChangeEvent<HTMLInputElement>) => {
setPasswordValue(event.target.value)
}}
onFocus={() => setIsPasswordFocused(true)}
onBlur={() => setIsPasswordFocused(false)}
placeholder={String(t('setPasswordView.form.newPassword'))}
label={t('setPasswordView.form.newPassword')}
withAsterisk
error={errors.password?.message}
classNames={{
label: classes['set-password-form__text-input--label'],
input: classes['set-password-form__text-input'],
}}
/>
</PasswordStrengthIndicator>

<ControlledPasswordInput
name="confirmPassword"
control={control}
placeholder={String(t('setPasswordView.form.confirmPassword'))}
label={t('setPasswordView.form.confirmPassword')}
withAsterisk
error={errors.confirmPassword?.message}
classNames={{
label: classes['set-password-form__text-input--label'],
input: classes['set-password-form__text-input'],
}}
/>

<Button fullWidth type="submit">
<Text size="sm" c="dimmed" mt={-8}>
{t('setPasswordView.form.passwordRequirements')}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This translation key does not exist, could you please take a look?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lwydra

i would appreciate a clearer explanation here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key setPasswordView.form.passwordRequirements does not exist in our translation files, leading to the key itself being rendered what is not very useful:

image

If you search for common.json, you will find our current translation files for german and english

</Text>

<Button
fullWidth
type="submit"
className={classes['set-password-form__submit-button']}
>
{t('setPasswordView.form.submit')}
</Button>
</Stack>
Expand Down
Loading