|
1 |
| -import React, { FC, useCallback, useEffect, useState } from 'react'; |
| 1 | +// TODO : Delete file once migration is done |
| 2 | +// import React, { FC, useCallback, useEffect, useState } from 'react'; |
2 | 3 |
|
3 |
| -import { Box, Flex, FlexProps, IconButton } from '@chakra-ui/react'; |
4 |
| -import { useFormContext, useFormFields } from '@formiz/core'; |
5 |
| -import { LuX } from 'react-icons/lu'; |
| 4 | +// import { Box, Flex, FlexProps, IconButton } from '@chakra-ui/react'; |
| 5 | +// import { useFormContext, useFormFields } from '@formiz/core'; |
| 6 | +// import { LuX } from 'react-icons/lu'; |
6 | 7 |
|
7 |
| -import { FieldUploadValue } from '@/components/FieldUpload'; |
| 8 | +// import { FieldUploadValue } from '@/components/FieldUpload'; |
8 | 9 |
|
9 |
| -const ImagePreview = ({ |
10 |
| - image, |
11 |
| - onClick, |
12 |
| -}: { |
13 |
| - image: string; |
14 |
| - onClick: React.MouseEventHandler<HTMLButtonElement>; |
15 |
| -}) => { |
16 |
| - return ( |
17 |
| - <Box |
18 |
| - position="relative" |
19 |
| - bg="gray.200" |
20 |
| - height="100%" |
21 |
| - aspectRatio="1" |
22 |
| - overflow="hidden" |
23 |
| - rounded="md" |
24 |
| - > |
25 |
| - <Box as="img" width="100%" height="100%" objectFit="cover" src={image} /> |
26 |
| - <IconButton |
27 |
| - position="absolute" |
28 |
| - top="1" |
29 |
| - right="1" |
30 |
| - icon={<LuX fontSize="sm" />} |
31 |
| - aria-label="Remove" |
32 |
| - rounded="full" |
33 |
| - minWidth="6" |
34 |
| - minHeight="6" |
35 |
| - width="6" |
36 |
| - height="6" |
37 |
| - onClick={onClick} |
38 |
| - /> |
39 |
| - </Box> |
40 |
| - ); |
41 |
| -}; |
| 10 | +// const ImagePreview = ({ |
| 11 | +// image, |
| 12 | +// onClick, |
| 13 | +// }: { |
| 14 | +// image: string; |
| 15 | +// onClick: React.MouseEventHandler<HTMLButtonElement>; |
| 16 | +// }) => { |
| 17 | +// return ( |
| 18 | +// <Box |
| 19 | +// position="relative" |
| 20 | +// bg="gray.200" |
| 21 | +// height="100%" |
| 22 | +// aspectRatio="1" |
| 23 | +// overflow="hidden" |
| 24 | +// rounded="md" |
| 25 | +// > |
| 26 | +// <Box as="img" width="100%" height="100%" objectFit="cover" src={image} /> |
| 27 | +// <IconButton |
| 28 | +// position="absolute" |
| 29 | +// top="1" |
| 30 | +// right="1" |
| 31 | +// icon={<LuX fontSize="sm" />} |
| 32 | +// aria-label="Remove" |
| 33 | +// rounded="full" |
| 34 | +// minWidth="6" |
| 35 | +// minHeight="6" |
| 36 | +// width="6" |
| 37 | +// height="6" |
| 38 | +// onClick={onClick} |
| 39 | +// /> |
| 40 | +// </Box> |
| 41 | +// ); |
| 42 | +// }; |
42 | 43 |
|
43 |
| -export type FieldUploadPreviewProps = FlexProps & { |
44 |
| - uploaderName: string; |
45 |
| -}; |
| 44 | +// export type FieldUploadPreviewProps = FlexProps & { |
| 45 | +// uploaderName: string; |
| 46 | +// }; |
46 | 47 |
|
47 |
| -export const FieldUploadPreview: FC< |
48 |
| - React.PropsWithChildren<FieldUploadPreviewProps> |
49 |
| -> = ({ uploaderName, ...rest }) => { |
50 |
| - const fields = useFormFields({ |
51 |
| - fields: [uploaderName] as const, // To get the uploader values |
52 |
| - }); |
53 |
| - const form = useFormContext(); |
| 48 | +// export const FieldUploadPreview: FC< |
| 49 | +// React.PropsWithChildren<FieldUploadPreviewProps> |
| 50 | +// > = ({ uploaderName, ...rest }) => { |
| 51 | +// const fields = useFormFields({ |
| 52 | +// fields: [uploaderName] as const, // To get the uploader values |
| 53 | +// }); |
| 54 | +// const form = useFormContext(); |
54 | 55 |
|
55 |
| - const [fileToPreview, setFileToPreview] = useState<string>(); |
| 56 | +// const [fileToPreview, setFileToPreview] = useState<string>(); |
56 | 57 |
|
57 |
| - const previewFile = useCallback(async () => { |
58 |
| - const uploaderFieldValue = fields?.[uploaderName] |
59 |
| - ?.value as FieldUploadValue; |
| 58 | +// const previewFile = useCallback(async () => { |
| 59 | +// const uploaderFieldValue = fields?.[uploaderName] |
| 60 | +// ?.value as FieldUploadValue; |
60 | 61 |
|
61 |
| - if ( |
62 |
| - !uploaderFieldValue || |
63 |
| - (!uploaderFieldValue.fileUrl && !uploaderFieldValue.file) |
64 |
| - ) { |
65 |
| - setFileToPreview(undefined); |
66 |
| - return; |
67 |
| - } |
| 62 | +// if ( |
| 63 | +// !uploaderFieldValue || |
| 64 | +// (!uploaderFieldValue.fileUrl && !uploaderFieldValue.file) |
| 65 | +// ) { |
| 66 | +// setFileToPreview(undefined); |
| 67 | +// return; |
| 68 | +// } |
68 | 69 |
|
69 |
| - const hasUserUploadedAFile = uploaderFieldValue.file; |
70 |
| - const hasDefaultFileSet = |
71 |
| - uploaderFieldValue.fileUrl && !hasUserUploadedAFile; |
| 70 | +// const hasUserUploadedAFile = uploaderFieldValue.file; |
| 71 | +// const hasDefaultFileSet = |
| 72 | +// uploaderFieldValue.fileUrl && !hasUserUploadedAFile; |
72 | 73 |
|
73 |
| - if (hasDefaultFileSet) { |
74 |
| - setFileToPreview(uploaderFieldValue.fileUrl); |
75 |
| - return; |
76 |
| - } |
| 74 | +// if (hasDefaultFileSet) { |
| 75 | +// setFileToPreview(uploaderFieldValue.fileUrl); |
| 76 | +// return; |
| 77 | +// } |
77 | 78 |
|
78 |
| - const uploadedFileToPreview = await new Promise<string>( |
79 |
| - (resolve, reject) => { |
80 |
| - const reader = new FileReader(); |
81 |
| - reader.onloadend = () => resolve(reader.result?.toString() ?? ''); |
82 |
| - reader.onerror = reject; |
83 |
| - if (uploaderFieldValue.file) { |
84 |
| - reader.readAsDataURL(uploaderFieldValue.file); |
85 |
| - } |
86 |
| - } |
87 |
| - ); |
| 79 | +// const uploadedFileToPreview = await new Promise<string>( |
| 80 | +// (resolve, reject) => { |
| 81 | +// const reader = new FileReader(); |
| 82 | +// reader.onloadend = () => resolve(reader.result?.toString() ?? ''); |
| 83 | +// reader.onerror = reject; |
| 84 | +// if (uploaderFieldValue.file) { |
| 85 | +// reader.readAsDataURL(uploaderFieldValue.file); |
| 86 | +// } |
| 87 | +// } |
| 88 | +// ); |
88 | 89 |
|
89 |
| - setFileToPreview(uploadedFileToPreview); |
90 |
| - }, [fields, uploaderName]); |
| 90 | +// setFileToPreview(uploadedFileToPreview); |
| 91 | +// }, [fields, uploaderName]); |
91 | 92 |
|
92 |
| - useEffect(() => { |
93 |
| - previewFile(); |
94 |
| - }, [previewFile]); |
| 93 | +// useEffect(() => { |
| 94 | +// previewFile(); |
| 95 | +// }, [previewFile]); |
95 | 96 |
|
96 |
| - return ( |
97 |
| - fileToPreview && ( |
98 |
| - <Flex |
99 |
| - mt={2} |
100 |
| - background="white" |
101 |
| - height="32" |
102 |
| - width="full" |
103 |
| - rounded="md" |
104 |
| - boxShadow="sm" |
105 |
| - border="1px solid" |
106 |
| - borderColor="gray.200" |
107 |
| - alignItems="center" |
108 |
| - p={4} |
109 |
| - {...rest} |
110 |
| - > |
111 |
| - <ImagePreview |
112 |
| - image={fileToPreview} |
113 |
| - onClick={() => { |
114 |
| - form.setValues({ [uploaderName]: null }); |
115 |
| - }} |
116 |
| - /> |
117 |
| - </Flex> |
118 |
| - ) |
119 |
| - ); |
120 |
| -}; |
| 97 | +// return ( |
| 98 | +// fileToPreview && ( |
| 99 | +// <Flex |
| 100 | +// mt={2} |
| 101 | +// background="white" |
| 102 | +// height="32" |
| 103 | +// width="full" |
| 104 | +// rounded="md" |
| 105 | +// boxShadow="sm" |
| 106 | +// border="1px solid" |
| 107 | +// borderColor="gray.200" |
| 108 | +// alignItems="center" |
| 109 | +// p={4} |
| 110 | +// {...rest} |
| 111 | +// > |
| 112 | +// <ImagePreview |
| 113 | +// image={fileToPreview} |
| 114 | +// onClick={() => { |
| 115 | +// form.setValues({ [uploaderName]: null }); |
| 116 | +// }} |
| 117 | +// /> |
| 118 | +// </Flex> |
| 119 | +// ) |
| 120 | +// ); |
| 121 | +// }; |
0 commit comments