From 6e50de1d28690479421dc4251217c8acaf55df82 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Wed, 29 May 2024 19:03:21 +0200 Subject: [PATCH] feat: style tweaks to upload attachments popover --- .../Attachments/AttachmentTransformer.ts | 4 +- .../UploadAttachmentButton.module.scss | 3 +- ...UploadAttachmentPopoverContent.module.scss | 34 +++++--- .../UploadAttachmentsPopoverContent.tsx | 78 +++++++++++++------ .../webapp/src/hooks/query/attachments.ts | 19 ++++- 5 files changed, 97 insertions(+), 41 deletions(-) diff --git a/packages/server/src/services/Attachments/AttachmentTransformer.ts b/packages/server/src/services/Attachments/AttachmentTransformer.ts index 8297b4f9c..e7cf70f91 100644 --- a/packages/server/src/services/Attachments/AttachmentTransformer.ts +++ b/packages/server/src/services/Attachments/AttachmentTransformer.ts @@ -6,7 +6,7 @@ export class AttachmentTransformer extends Transformer { * @returns {string[]} */ public excludeAttributes = (): string[] => { - return ['*']; + return ['id', 'createdAt']; }; /** @@ -14,6 +14,6 @@ export class AttachmentTransformer extends Transformer { * @returns {string[]} */ public includeAttributes = (): string[] => { - return ['extension', 'key']; + return []; }; } diff --git a/packages/webapp/src/containers/Attachments/UploadAttachmentButton.module.scss b/packages/webapp/src/containers/Attachments/UploadAttachmentButton.module.scss index f1ccd5a93..1fc37bfc4 100644 --- a/packages/webapp/src/containers/Attachments/UploadAttachmentButton.module.scss +++ b/packages/webapp/src/containers/Attachments/UploadAttachmentButton.module.scss @@ -1,9 +1,8 @@ .popover :global .bp4-popover-content{ - min-width: 450px; + min-width: 600px; } - .attachmentButton:not([class*=bp4-intent-]) { &, &:hover{ diff --git a/packages/webapp/src/containers/Attachments/UploadAttachmentPopoverContent.module.scss b/packages/webapp/src/containers/Attachments/UploadAttachmentPopoverContent.module.scss index 6753ccaaa..791ad18ca 100644 --- a/packages/webapp/src/containers/Attachments/UploadAttachmentPopoverContent.module.scss +++ b/packages/webapp/src/containers/Attachments/UploadAttachmentPopoverContent.module.scss @@ -4,9 +4,9 @@ .hintText{ display: flex; - font-size: 12px; + font-size: 11px; margin-top: 6px; - color: #8F99A8; + color: #738091; justify-content: space-between; } @@ -15,27 +15,36 @@ } .attachmentItem{ - border: 1px solid #D3D8DE; - border-radius: 3px; - padding: 6px 10px; + border-top: 1px solid #D3D8DE; + border-left: 1px solid #D3D8DE; + border-right: 1px solid #D3D8DE; + padding: 10px 14px; justify-content: space-between; + + &:first-child { + border-radius: 3px 3px 0 0; + } + &:last-child{ + border-radius: 0 0 3px 3px; + border-bottom: 1px solid #D3D8DE; + } } .attachmentFilenameText{ - color: #404854; + } -.attachmentSizeText{ - font-size: 12px; +.attachmentSizeText, +.attachmentLoadingText{ + font-size: 13px; color: #738091; } .attachmentContent{ - padding-left: 8px; } .attachmentIcon{ - color: #8F99A8; + color: #626b7c; } .label{ @@ -47,3 +56,8 @@ min-height: 140px; padding: 10px; } + +.attachmentIconWrap{ + width: 20PX; + text-align: right; +} \ No newline at end of file diff --git a/packages/webapp/src/containers/Attachments/UploadAttachmentsPopoverContent.tsx b/packages/webapp/src/containers/Attachments/UploadAttachmentsPopoverContent.tsx index be4c84374..25a4c5222 100644 --- a/packages/webapp/src/containers/Attachments/UploadAttachmentsPopoverContent.tsx +++ b/packages/webapp/src/containers/Attachments/UploadAttachmentsPopoverContent.tsx @@ -1,4 +1,5 @@ // @ts-nocheck +import { useState } from 'react'; import { isEmpty } from 'lodash'; import { Button, Intent, Text, Spinner } from '@blueprintjs/core'; import { Box, Group, Icon, Stack } from '@/components'; @@ -7,7 +8,10 @@ import { ImportDropzoneFieldProps, } from '@/containers/Import/ImportDropzoneFile'; import { useUncontrolled } from '@/hooks/useUncontrolled'; -import { useUploadAttachments } from '@/hooks/query/attachments'; +import { + useGetPresignedUrlAttachment, + useUploadAttachments, +} from '@/hooks/query/attachments'; import { formatBytes } from '../Sales/Invoices/InvoiceForm/utils'; import styles from './UploadAttachmentPopoverContent.module.scss'; import { MIME_TYPES } from '@/components/Dropzone/mine-types'; @@ -20,7 +24,7 @@ interface AttachmentFileCommon { } interface AttachmentFileLoaded extends AttachmentFileCommon {} interface AttachmentFileLoading extends AttachmentFileCommon { - _loading: boolean; + loading: boolean; } type AttachmentFile = AttachmentFileLoaded | AttachmentFileLoading; @@ -62,7 +66,7 @@ export function UploadAttachmentsPopoverContent({ return { ...localFile, key: newKey, - _loading: false, + loading: false, }; } return localFile; @@ -100,7 +104,7 @@ export function UploadAttachmentsPopoverContent({ originName: file.name, size: file.size, key, - _loading: true, + loading: true, }, ...localFiles, ]); @@ -130,35 +134,38 @@ export function UploadAttachmentsPopoverContent({ {...dropzoneFieldProps} /> - Formats: CSV, XLSX Maximum: 25MB {!isEmpty(localFiles) && ( - + {localFiles.map((localFile: AttachmentFile, index: number) => ( - - {localFile._loading ? ( - - ) : ( - - )} + +
+ {localFile.loading ? ( + + ) : ( + + )} +
{localFile.originName} - {localFile._loading ? ( - Loading... + {localFile.loading ? ( + + Loading... + ) : ( {formatBytes(localFile.size)} @@ -167,11 +174,9 @@ export function UploadAttachmentsPopoverContent({
- {!localFile._loading && ( - - + {!localFile.loading && ( + + + ); +}; diff --git a/packages/webapp/src/hooks/query/attachments.ts b/packages/webapp/src/hooks/query/attachments.ts index a9a40972c..4255e3d0a 100644 --- a/packages/webapp/src/hooks/query/attachments.ts +++ b/packages/webapp/src/hooks/query/attachments.ts @@ -2,10 +2,6 @@ import { useMutation } from 'react-query'; import useApiRequest from '../useRequest'; -const commonInvalidateQueries = (query) => { - // Invalidate accounts. -}; - /** * Uploads the given attachments. */ @@ -29,3 +25,18 @@ export function useDeleteAttachment(props) { props, ); } + +/** + * Uploads the given attachments. + */ +export function useGetPresignedUrlAttachment(props) { + const apiRequest = useApiRequest(); + + return useMutation( + (key: string) => + apiRequest + .get(`/attachments/${key}/presigned-url`) + .then((res) => res.data), + props, + ); +}