diff --git a/apps/storybook/src/stories/Attachment.stories.tsx b/apps/storybook/src/stories/Attachment.stories.tsx new file mode 100644 index 00000000..82075771 --- /dev/null +++ b/apps/storybook/src/stories/Attachment.stories.tsx @@ -0,0 +1,109 @@ +import { ApiProvider } from "@repo/apis/providers/api-provider"; +import { AttachmentAdmin } from "@repo/ui/components/attachment/attachmentAdmin/attachmentAdmin"; +import { AttachmentLanding } from "@repo/ui/components/attachment/attachmentLanding/attachmentLanding"; +import { + AttachmentThumbnail, + AttachmentThumbnailProps, +} from "@repo/ui/components/attachment/attachmentThumbnail/attachmentThumbnail"; +import { AttachmentProps } from "@repo/ui/components/attachment/useAttachment"; +import type { Meta, StoryObj } from "@storybook/react"; + +const meta: Meta> = { + title: "Components/Attachment", + tags: ["autodocs"], + + argTypes: { + title: { control: "text" }, + fileCategory: { control: "radio", options: ["request_author", "product"] }, + onChange: { action: "changed" }, + multiple: { type: "boolean" }, + maxSize: { type: "number" }, + disabled: { type: "boolean" }, + error: { type: "string" }, + canDeleteFile: { type: "boolean" }, + allowedTypes: { control: "object", description: "Array of strings" }, + price: { type: "number" }, + username: { type: "string" }, + priceUnit: { type: "string" }, + productName: { type: "string" }, + avatar: { type: "string" }, + }, + args: { + multiple: false, + allowedTypes: ["jpg", "jpeg", "png"], + fileCategory: "request_author", + onChange: (fileIds: number[] | []) => { + console.log(fileIds); + }, + }, +}; + +export default meta; +type Story = StoryObj; + +// ✅ **Individual Button Stories** +export const Dashboard: Story = { + args: { + title: "Upload Your CV and Portfolio", + onChange: (filesId: number[]) => { + console.log(filesId); + }, + fileCategory: "request_author", + }, + render: (args) => ( + + + + ), +}; + +export const Landing: Story = { + args: { + title: "Upload Your CV and Portfolio", + onChange: (filesId: number[]) => { + console.log(filesId); + }, + fileCategory: "request_author", + }, + render: (args) => ( + + + + ), +}; + +export const Thumbnail: Story = { + argTypes: { + price: { control: "number" }, + productName: { control: "text" }, + username: { control: "text" }, + }, + args: { + title: "Upload Your CV and Portfolio", + onChange: (filesId: number[]) => { + console.log(filesId); + }, + fileCategory: "request_author", + }, + render: (args) => ( + + + + ), +}; diff --git a/packages/ui/src/components/molecules/attachment/attachmentAdmin/attachmentAdmin.tsx b/packages/ui/src/components/molecules/attachment/attachmentAdmin/attachmentAdmin.tsx index 9d4c17bb..ed38ddba 100644 --- a/packages/ui/src/components/molecules/attachment/attachmentAdmin/attachmentAdmin.tsx +++ b/packages/ui/src/components/molecules/attachment/attachmentAdmin/attachmentAdmin.tsx @@ -10,10 +10,9 @@ const AttachmentAdmin = (props: AttachmentProps) => { const { title, multiple = false, maxSize = 10, allowedTypes } = props; const { inputFileRef, handleChange, handleRemove, files, allowedTypesText } = useAttachment(props); - return ( <> - +
{ initial={{ opacity: 0, scale: 0.95 }} animate={{ opacity: 1, scale: 1 }} > - + {files.map((file) => ( { {file.loading ? null : ( @@ -51,16 +51,10 @@ const AttachmentItem = ({ file, handleRemove }: AttachmentItemProps) => { {file.type} )}
-

- - {file.name.slice(0, file.name.lastIndexOf(".") - 1)} - - - {file.name.slice(file.name.lastIndexOf("."), file.name.length)} - +

+ + {file.name} +

{(file.size / 1024 / 1024).toFixed(2)}mb diff --git a/packages/ui/src/components/molecules/attachment/attachmentThumbnail/attachmentThumbnail.tsx b/packages/ui/src/components/molecules/attachment/attachmentThumbnail/attachmentThumbnail.tsx index b545a240..a5f9f2df 100644 --- a/packages/ui/src/components/molecules/attachment/attachmentThumbnail/attachmentThumbnail.tsx +++ b/packages/ui/src/components/molecules/attachment/attachmentThumbnail/attachmentThumbnail.tsx @@ -9,7 +9,7 @@ import { useState } from "react"; import { Card } from "../../../atoms/card"; import Typography from "@repo/ui/components/typography"; -interface AttachmentThumbnailProps extends AttachmentProps { +export interface AttachmentThumbnailProps extends AttachmentProps { avatar?: string; price: number; priceUnit?: string; @@ -38,7 +38,7 @@ const AttachmentThumbnail = ( return ( @@ -155,7 +155,9 @@ const AttachmentThumbnail = ( ) : ( )} - Ali Ebrahimi Kashef + + Ali Ebrahimi Kashef +

diff --git a/packages/ui/src/components/molecules/attachment/useAttachment.ts b/packages/ui/src/components/molecules/attachment/useAttachment.ts index ccea8ff9..2e54f151 100644 --- a/packages/ui/src/components/molecules/attachment/useAttachment.ts +++ b/packages/ui/src/components/molecules/attachment/useAttachment.ts @@ -94,6 +94,7 @@ const useAttachment = ({ file.type.slice(file.type.lastIndexOf("/") + 1, file.type.length), ), ); + console.log(allowedTypes); if (includesType) { const maxSizeBytes = maxSize * 1024 * 1024; const validSize = filesInput.every((file) => file.size <= maxSizeBytes);