Skip to content

Commit

Permalink
Merge pull request #34 from Project-Unifest/fix/validate-id-and-password
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
algoORgoal authored Jul 14, 2024
2 parents fcc1926 + ce52522 commit fe4b06d
Show file tree
Hide file tree
Showing 15 changed files with 18,836 additions and 12,272 deletions.
14 changes: 11 additions & 3 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@ const config: StorybookConfig = {
"../stories/**/*.mdx",
"../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)",
],

addons: [
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
"@storybook/addon-coverage",
"@storybook/addon-mdx-gfm"
],

framework: {
name: "@storybook/nextjs",
options: {},
},
docs: {
autodocs: "tag",
},

docs: {},

staticDirs: [
"../public",
{
from: "../static/fonts",
to: "static/fonts",
},
],

features: {
experimentalRSC: true,
},

typescript: {
reactDocgen: "react-docgen-typescript"
}
};
export default config;
1 change: 1 addition & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const preview: Preview = {
},
// Provide the MSW addon loader globally
loaders: [mswLoader],
tags: ["autodocs"],
};

export default preview;
894 changes: 894 additions & 0 deletions .yarn/releases/yarn-4.3.1.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.3.1.cjs
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@
"zustand": "^4.5.2"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.3.2",
"@chromatic-com/storybook": "^1.6.1",
"@faker-js/faker": "^8.4.1",
"@playwright/test": "^1.43.1",
"@storybook/addon-coverage": "^1.0.1",
"@storybook/addon-essentials": "^8.0.8",
"@storybook/addon-interactions": "^8.0.8",
"@storybook/addon-links": "^8.0.8",
"@storybook/addon-onboarding": "^8.0.8",
"@storybook/blocks": "^8.0.8",
"@storybook/nextjs": "^8.0.8",
"@storybook/react": "^8.0.8",
"@storybook/test": "^8.0.8",
"@storybook/test-runner": "^0.17.0",
"@storybook/addon-coverage": "^1.0.4",
"@storybook/addon-essentials": "^8.2.1",
"@storybook/addon-interactions": "^8.2.1",
"@storybook/addon-links": "^8.2.1",
"@storybook/addon-mdx-gfm": "^8.2.1",
"@storybook/addon-onboarding": "^8.2.1",
"@storybook/blocks": "^8.2.1",
"@storybook/nextjs": "^8.2.1",
"@storybook/react": "^8.2.1",
"@storybook/test": "^8.2.1",
"@storybook/test-runner": "^0.19.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand All @@ -65,18 +66,19 @@
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"msw": "^2.2.14",
"msw-storybook-addon": "^2.0.0-beta.2",
"msw-storybook-addon": "^2.0.2",
"nyc": "^15.1.0",
"playwright-msw": "^3.0.1",
"postcss": "^8.4.38",
"prettier-plugin-tailwindcss": "^0.5.14",
"storybook": "^8.0.8",
"storybook": "^8.2.1",
"tailwindcss": "^3.4.1",
"typescript": "^5"
},
"msw": {
"workerDirectory": [
"public"
]
}
},
"packageManager": "[email protected]"
}
118 changes: 61 additions & 57 deletions src/shared/ui/form.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { Slot } from "@radix-ui/react-slot"
import * as React from "react";
import * as LabelPrimitive from "@radix-ui/react-label";
import { Slot } from "@radix-ui/react-slot";
import {
Controller,
ControllerProps,
FieldPath,
FieldValues,
FormProvider,
useFormContext,
} from "react-hook-form"
} from "react-hook-form";

import { cn } from "@/src/shared/lib/utils"
import { Label } from "@/src/shared/ui/label"
import { cn } from "@/src/shared/lib/utils";
import { Label } from "@/src/shared/ui/label";

const Form = FormProvider
const Form = FormProvider;

type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> = {
name: TName
}
name: TName;
};

const FormFieldContext = React.createContext<FormFieldContextValue>(
{} as FormFieldContextValue
)
{} as FormFieldContextValue,
);

const FormField = <
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>({
...props
}: ControllerProps<TFieldValues, TName>) => {
return (
<FormFieldContext.Provider value={{ name: props.name }}>
<Controller {...props} />
</FormFieldContext.Provider>
)
}
);
};

const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext)
const itemContext = React.useContext(FormItemContext)
const { getFieldState, formState } = useFormContext()
const fieldContext = React.useContext(FormFieldContext);
const itemContext = React.useContext(FormItemContext);
const { getFieldState, formState } = useFormContext();

const fieldState = getFieldState(fieldContext.name, formState)
const fieldState = getFieldState(fieldContext.name, formState);

if (!fieldContext) {
throw new Error("useFormField should be used within <FormField>")
throw new Error("useFormField should be used within <FormField>");
}

const { id } = itemContext
const { id } = itemContext;

return {
id,
Expand All @@ -59,36 +59,36 @@ const useFormField = () => {
formDescriptionId: `${id}-form-item-description`,
formMessageId: `${id}-form-item-message`,
...fieldState,
}
}
};
};

type FormItemContextValue = {
id: string
}
id: string;
};

const FormItemContext = React.createContext<FormItemContextValue>(
{} as FormItemContextValue
)
{} as FormItemContextValue,
);

const FormItem = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => {
const id = React.useId()
const id = React.useId();

return (
<FormItemContext.Provider value={{ id }}>
<div ref={ref} className={cn("space-y-2", className)} {...props} />
</FormItemContext.Provider>
)
})
FormItem.displayName = "FormItem"
);
});
FormItem.displayName = "FormItem";

const FormLabel = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
>(({ className, ...props }, ref) => {
const { error, formItemId } = useFormField()
const { error, formItemId } = useFormField();

return (
<Label
Expand All @@ -97,72 +97,76 @@ const FormLabel = React.forwardRef<
htmlFor={formItemId}
{...props}
/>
)
})
FormLabel.displayName = "FormLabel"
);
});
FormLabel.displayName = "FormLabel";

const FormControl = React.forwardRef<
React.ElementRef<typeof Slot>,
React.ComponentPropsWithoutRef<typeof Slot>
>(({ ...props }, ref) => {
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
const { error, formItemId, formDescriptionId, formMessageId } =
useFormField();

return (
<Slot
ref={ref}
id={formItemId}
aria-describedby={
!error
? `${formDescriptionId}`
: `${formDescriptionId} ${formMessageId}`
}
aria-describedby={formDescriptionId}
aria-errormessage={!error ? undefined : formMessageId}
aria-invalid={!!error}
{...props}
/>
)
})
FormControl.displayName = "FormControl"
);
});
FormControl.displayName = "FormControl";

const FormDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => {
const { formDescriptionId } = useFormField()
const { formDescriptionId } = useFormField();

return (
<p
ref={ref}
id={formDescriptionId}
className={cn("text-[0.8rem] text-slate-500 dark:text-slate-400", className)}
className={cn(
"text-[0.8rem] text-slate-500 dark:text-slate-400",
className,
)}
{...props}
/>
)
})
FormDescription.displayName = "FormDescription"
);
});
FormDescription.displayName = "FormDescription";

const FormMessage = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, children, ...props }, ref) => {
const { error, formMessageId } = useFormField()
const body = error ? String(error?.message) : children
const { error, formMessageId } = useFormField();
const body = error ? String(error?.message) : children;

if (!body) {
return null
return null;
}

return (
<p
ref={ref}
id={formMessageId}
className={cn("text-[0.8rem] font-medium text-red-500 dark:text-red-900", className)}
className={cn(
"text-[0.8rem] font-medium text-red-500 dark:text-red-900",
className,
)}
{...props}
>
{body}
</p>
)
})
FormMessage.displayName = "FormMessage"
);
});
FormMessage.displayName = "FormMessage";

export {
useFormField,
Expand All @@ -173,4 +177,4 @@ export {
FormDescription,
FormMessage,
FormField,
}
};
Loading

1 comment on commit fe4b06d

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for unifest-web-deployment ready!

✅ Preview
https://unifest-web-deployment-1jr9djq2v-algoorgoals-projects.vercel.app

Built with commit fe4b06d.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.