Merged in fix/3697-prettier-configs (pull request #3396)
fix(SW-3691): Setup one prettier config for whole repo * Setup prettierrc in root and remove other configs Approved-by: Joakim Jäderberg Approved-by: Linus Flood
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
|
||||
import { fn } from 'storybook/test'
|
||||
import { useEffect } from 'react'
|
||||
import { FormProvider, useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { z } from 'zod'
|
||||
import type { IntlShape } from 'react-intl'
|
||||
import type { Meta, StoryObj } from "@storybook/nextjs-vite"
|
||||
import { fn } from "storybook/test"
|
||||
import { useEffect } from "react"
|
||||
import { FormProvider, useForm } from "react-hook-form"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { z } from "zod"
|
||||
import type { IntlShape } from "react-intl"
|
||||
|
||||
import { PasswordInput } from './index'
|
||||
import { Button } from '../Button'
|
||||
import { Typography } from '../Typography'
|
||||
import { passwordValidator } from '@scandic-hotels/common/utils/zod/passwordValidator'
|
||||
import { PasswordInput } from "./index"
|
||||
import { Button } from "../Button"
|
||||
import { Typography } from "../Typography"
|
||||
import { passwordValidator } from "@scandic-hotels/common/utils/zod/passwordValidator"
|
||||
|
||||
// Simple error formatter for Storybook
|
||||
const defaultErrorFormatter = (
|
||||
_intl: IntlShape,
|
||||
errorMessage?: string
|
||||
): string => errorMessage ?? ''
|
||||
): string => errorMessage ?? ""
|
||||
|
||||
// ============================================================================
|
||||
// Password Form with New Password Validation
|
||||
@@ -24,15 +24,15 @@ const defaultErrorFormatter = (
|
||||
const passwordFormSchema = z
|
||||
.object({
|
||||
currentPassword: z.string().optional(),
|
||||
newPassword: z.literal('').optional().or(passwordValidator()),
|
||||
newPassword: z.literal("").optional().or(passwordValidator()),
|
||||
confirmPassword: z.string().optional(),
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
if (data.newPassword && data.newPassword !== data.confirmPassword) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Passwords do not match',
|
||||
path: ['confirmPassword'],
|
||||
code: "custom",
|
||||
message: "Passwords do not match",
|
||||
path: ["confirmPassword"],
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -48,18 +48,18 @@ interface PasswordInputProps {
|
||||
function PasswordInputComponent({
|
||||
onSubmit,
|
||||
showErrors = false,
|
||||
defaultNewPassword = '',
|
||||
defaultNewPassword = "",
|
||||
}: PasswordInputProps) {
|
||||
const methods = useForm<PasswordFormData>({
|
||||
resolver: zodResolver(passwordFormSchema),
|
||||
defaultValues: {
|
||||
currentPassword: '',
|
||||
currentPassword: "",
|
||||
newPassword: defaultNewPassword,
|
||||
confirmPassword: '',
|
||||
confirmPassword: "",
|
||||
},
|
||||
mode: 'all',
|
||||
criteriaMode: 'all',
|
||||
reValidateMode: 'onChange',
|
||||
mode: "all",
|
||||
criteriaMode: "all",
|
||||
reValidateMode: "onChange",
|
||||
})
|
||||
|
||||
// Trigger validation on mount if showErrors is true
|
||||
@@ -78,10 +78,10 @@ function PasswordInputComponent({
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '1.5rem',
|
||||
maxWidth: '500px',
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "1.5rem",
|
||||
maxWidth: "500px",
|
||||
}}
|
||||
>
|
||||
<Typography variant="Title/md">
|
||||
@@ -115,19 +115,19 @@ function PasswordInputComponent({
|
||||
}
|
||||
|
||||
const passwordFormMeta: Meta<typeof PasswordInputComponent> = {
|
||||
title: 'Core Components/PasswordInput',
|
||||
title: "Core Components/PasswordInput",
|
||||
component: PasswordInputComponent,
|
||||
parameters: {
|
||||
layout: 'padded',
|
||||
layout: "padded",
|
||||
},
|
||||
argTypes: {
|
||||
showErrors: {
|
||||
control: 'boolean',
|
||||
description: 'Show validation errors on mount',
|
||||
control: "boolean",
|
||||
description: "Show validation errors on mount",
|
||||
},
|
||||
defaultNewPassword: {
|
||||
control: 'text',
|
||||
description: 'Default value for new password field',
|
||||
control: "text",
|
||||
description: "Default value for new password field",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -141,7 +141,7 @@ export const Default: PasswordFormStory = {
|
||||
args: {
|
||||
onSubmit: fn(),
|
||||
showErrors: false,
|
||||
defaultNewPassword: '',
|
||||
defaultNewPassword: "",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ export const Default: PasswordFormStory = {
|
||||
// ============================================================================
|
||||
|
||||
const showcasePasswordSchema = z.object({
|
||||
empty: z.literal('').optional().or(passwordValidator()),
|
||||
empty: z.literal("").optional().or(passwordValidator()),
|
||||
weak: passwordValidator(),
|
||||
partial: passwordValidator(),
|
||||
valid: passwordValidator(),
|
||||
@@ -163,31 +163,31 @@ function PasswordValidationShowcase() {
|
||||
const methods = useForm<ShowcasePasswordFormData>({
|
||||
resolver: zodResolver(showcasePasswordSchema),
|
||||
defaultValues: {
|
||||
empty: '',
|
||||
weak: 'weak',
|
||||
partial: 'Password1',
|
||||
valid: 'ValidPassword123!',
|
||||
tooLong: 'A'.repeat(41) + '1!',
|
||||
empty: "",
|
||||
weak: "weak",
|
||||
partial: "Password1",
|
||||
valid: "ValidPassword123!",
|
||||
tooLong: "A".repeat(41) + "1!",
|
||||
},
|
||||
mode: 'all',
|
||||
criteriaMode: 'all',
|
||||
reValidateMode: 'onChange',
|
||||
mode: "all",
|
||||
criteriaMode: "all",
|
||||
reValidateMode: "onChange",
|
||||
})
|
||||
|
||||
// Trigger validation on mount to show validation states
|
||||
useEffect(() => {
|
||||
methods.trigger(['weak', 'partial', 'valid', 'tooLong'])
|
||||
methods.trigger(["weak", "partial", "valid", "tooLong"])
|
||||
}, [methods])
|
||||
|
||||
return (
|
||||
<FormProvider {...methods}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: '3rem',
|
||||
maxWidth: '800px',
|
||||
padding: '2rem',
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "3rem",
|
||||
maxWidth: "800px",
|
||||
padding: "2rem",
|
||||
}}
|
||||
>
|
||||
<section>
|
||||
@@ -196,10 +196,10 @@ function PasswordValidationShowcase() {
|
||||
</Typography>
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(auto-fit, minmax(350px, 1fr))',
|
||||
gap: '2rem',
|
||||
marginTop: '1rem',
|
||||
display: "grid",
|
||||
gridTemplateColumns: "repeat(auto-fit, minmax(350px, 1fr))",
|
||||
gap: "2rem",
|
||||
marginTop: "1rem",
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
@@ -264,10 +264,10 @@ function PasswordValidationShowcase() {
|
||||
}
|
||||
|
||||
const showcaseMeta: Meta<typeof PasswordValidationShowcase> = {
|
||||
title: 'Core Components/PasswordInput',
|
||||
title: "Core Components/PasswordInput",
|
||||
component: PasswordValidationShowcase,
|
||||
parameters: {
|
||||
layout: 'fullscreen',
|
||||
layout: "fullscreen",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user