@sikka/hawa 0.0.34 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/index.es.js +1 -1
- package/lib/index.js +1 -1
- package/package.json +4 -2
- package/src/elements/AdaptiveButton.js +1 -1
- package/src/elements/DragDropImages.js +149 -140
- package/src/elements/DraggableCard.js +36 -0
- package/src/elements/index.js +2 -0
- package/storybook-static/iframe.html +1 -1
- package/storybook-static/index.html +1 -1
- package/storybook-static/main.6eab4ef6.iframe.bundle.js +1 -0
- package/storybook-static/vendors~main.07e1611f.iframe.bundle.js +76 -0
- package/storybook-static/{vendors~main.a7262b49.iframe.bundle.js.LICENSE.txt → vendors~main.07e1611f.iframe.bundle.js.LICENSE.txt} +0 -0
- package/storybook-static/vendors~main.07e1611f.iframe.bundle.js.map +1 -0
- package/storybook-static/{vendors~main.a697e07137d366f95f76.manager.bundle.js → vendors~main.11281b487bf96f5ff19e.manager.bundle.js} +2 -2
- package/storybook-static/{vendors~main.a697e07137d366f95f76.manager.bundle.js.LICENSE.txt → vendors~main.11281b487bf96f5ff19e.manager.bundle.js.LICENSE.txt} +0 -0
- package/storybook-static/main.e9b7f5c4.iframe.bundle.js +0 -1
- package/storybook-static/vendors~main.a7262b49.iframe.bundle.js +0 -76
- package/storybook-static/vendors~main.a7262b49.iframe.bundle.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
// import axios from "axios";
|
|
3
|
-
import { getToken } from "../token";
|
|
4
3
|
import { useDropzone } from "react-dropzone";
|
|
5
|
-
import useTranslation from "next-translate/useTranslation";
|
|
6
|
-
import Badge from "@mui/material/Badge";
|
|
7
4
|
import CloseIcon from "@mui/icons-material/Close";
|
|
8
|
-
import
|
|
5
|
+
// import styled from "@emotion/styled";
|
|
6
|
+
import { Container, IconButton, Typography } from "@mui/material";
|
|
7
|
+
import { useTheme } from "@mui/system";
|
|
8
|
+
import { HawaAlert } from "./HawaAlert";
|
|
9
9
|
|
|
10
10
|
const thumbsContainer = {
|
|
11
11
|
display: "flex",
|
|
@@ -14,23 +14,31 @@ const thumbsContainer = {
|
|
|
14
14
|
marginTop: 10
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
export const DragDropImages = ({
|
|
18
|
+
texts,
|
|
18
19
|
files,
|
|
19
20
|
setFiles,
|
|
20
21
|
itemId,
|
|
21
22
|
setDeletedFiles,
|
|
22
|
-
refetchSingleMenu
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
refetchSingleMenu,
|
|
24
|
+
maxFiles
|
|
25
|
+
}) =>
|
|
26
|
+
// props
|
|
27
|
+
{
|
|
28
|
+
const [cmp, setCmp] = useState(0);
|
|
29
|
+
//const [thumbs, setThumbs] = useState("");
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
const {
|
|
32
|
+
getRootProps,
|
|
33
|
+
getInputProps,
|
|
34
|
+
fileRejections,
|
|
35
|
+
acceptedFiles,
|
|
36
|
+
isDragActive
|
|
37
|
+
} = useDropzone({
|
|
38
|
+
multiple: true,
|
|
31
39
|
accept: "image/*",
|
|
32
40
|
maxSize: 5000000,
|
|
33
|
-
maxFiles:
|
|
41
|
+
maxFiles: maxFiles,
|
|
34
42
|
onDrop: (acceptedFiles) => {
|
|
35
43
|
setFiles(
|
|
36
44
|
acceptedFiles.map((file, index) =>
|
|
@@ -41,140 +49,141 @@ const DragDropItemImage = ({
|
|
|
41
49
|
);
|
|
42
50
|
}
|
|
43
51
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
const handleRemoveFile = async (file) => {
|
|
53
|
+
console.log("fezafezaf", acceptedFiles[file]);
|
|
54
|
+
if (acceptedFiles[file]?.isFromDB) {
|
|
55
|
+
setDeletedFiles((old) => [
|
|
56
|
+
...old,
|
|
57
|
+
{
|
|
58
|
+
img_url: acceptedFiles[file]?.img_url,
|
|
59
|
+
_id: acceptedFiles[file]?._id
|
|
60
|
+
}
|
|
61
|
+
]);
|
|
62
|
+
try {
|
|
63
|
+
// await axios.post(
|
|
64
|
+
// `${process.env.NEXT_PUBLIC_QAWAIM_API_URL}/deleteImages`,
|
|
65
|
+
// {
|
|
66
|
+
// deletedFiles: [
|
|
67
|
+
// {
|
|
68
|
+
// img_url: acceptedFiles[file]?.img_url,
|
|
69
|
+
// _id: acceptedFiles[file]?._id
|
|
70
|
+
// }
|
|
71
|
+
// ],
|
|
72
|
+
// itemId: itemId
|
|
73
|
+
// }
|
|
74
|
+
// );
|
|
75
|
+
refetchSingleMenu();
|
|
76
|
+
acceptedFiles.splice(file, 1);
|
|
77
|
+
setFiles(acceptedFiles);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error(err);
|
|
52
80
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// `${process.env.NEXT_PUBLIC_QAWAIM_API_URL}/deleteImages`,
|
|
57
|
-
// {
|
|
58
|
-
// deletedFiles: [
|
|
59
|
-
// {
|
|
60
|
-
// img_url: acceptedFiles[file]?.img_url,
|
|
61
|
-
// _id: acceptedFiles[file]?._id
|
|
62
|
-
// }
|
|
63
|
-
// ],
|
|
64
|
-
// itemId: itemId
|
|
65
|
-
// }
|
|
66
|
-
// );
|
|
67
|
-
refetchSingleMenu();
|
|
68
|
-
acceptedFiles.splice(file, 1);
|
|
69
|
-
setFiles(acceptedFiles);
|
|
70
|
-
} catch (err) {
|
|
71
|
-
console.error(err);
|
|
81
|
+
console.log("accepted files after delete : ", acceptedFiles);
|
|
82
|
+
setCmp((old) => old + 1);
|
|
83
|
+
return;
|
|
72
84
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// console.log("Yes");
|
|
79
|
-
// return;
|
|
80
|
-
// }
|
|
81
|
-
acceptedFiles.splice(file, 1);
|
|
85
|
+
// if (file.hasOwnProperty("_id")) {
|
|
86
|
+
// console.log("Yes");
|
|
87
|
+
// return;
|
|
88
|
+
// }
|
|
89
|
+
acceptedFiles.splice(file, 1);
|
|
82
90
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
setFiles(
|
|
92
|
+
acceptedFiles.map((f) =>
|
|
93
|
+
Object.assign(f, { preview: URL.createObjectURL(f) })
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
// setFiles(acceptedFiles);
|
|
97
|
+
};
|
|
98
|
+
useEffect(
|
|
99
|
+
() => () => {
|
|
100
|
+
files?.forEach((file) => {
|
|
101
|
+
URL.revokeObjectURL(file.preview);
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
[files]
|
|
87
105
|
);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
[files]
|
|
98
|
-
);
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
if (files[0]?.hasOwnProperty("_id")) {
|
|
101
|
-
files?.map((file, index) => {
|
|
102
|
-
acceptedFiles.push({
|
|
103
|
-
preview: `https://qawaim-images.s3-ap-southeast-1.amazonaws.com/${file.image_url}`,
|
|
104
|
-
isFromDB: true,
|
|
105
|
-
_id: file._id,
|
|
106
|
-
img_url: file.image_url
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (files[0]?.hasOwnProperty("_id")) {
|
|
108
|
+
files?.map((file, index) => {
|
|
109
|
+
acceptedFiles.push({
|
|
110
|
+
// preview: `https://qawaim-images.s3-ap-southeast-1.amazonaws.com/${file.image_url}`,
|
|
111
|
+
isFromDB: true,
|
|
112
|
+
_id: file._id,
|
|
113
|
+
img_url: file.image_url
|
|
114
|
+
});
|
|
107
115
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
console.log("accepted files : ", acceptedFiles);
|
|
117
|
+
setFiles(acceptedFiles);
|
|
118
|
+
}
|
|
119
|
+
return () => {
|
|
120
|
+
acceptedFiles.splice(0, acceptedFiles?.length);
|
|
121
|
+
};
|
|
122
|
+
}, []);
|
|
123
|
+
const errs = fileRejections.map((rej, i) => {
|
|
124
|
+
return (
|
|
125
|
+
<div key={i}>
|
|
126
|
+
<div>{rej.file.name}</div>
|
|
127
|
+
<div>{rej.errors[0].code}</div>
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
console.log(fileRejections[0]?.errors[0]?.code);
|
|
132
|
+
const thumbs = files?.map((file, index) => (
|
|
133
|
+
<div style={{ position: "relative", margin: 10 }}>
|
|
134
|
+
<IconButton
|
|
135
|
+
onClick={(e) => {
|
|
136
|
+
e.stopPropagation();
|
|
137
|
+
console.log("delete");
|
|
138
|
+
}}
|
|
139
|
+
size="small"
|
|
140
|
+
variant="contained"
|
|
141
|
+
style={{
|
|
142
|
+
position: "absolute",
|
|
143
|
+
top: -10,
|
|
144
|
+
right: -10,
|
|
145
|
+
backgroundColor: theme.primaryActionColor,
|
|
146
|
+
color: "white",
|
|
147
|
+
padding: 3
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<CloseIcon fontSize="small" />
|
|
151
|
+
</IconButton>
|
|
152
|
+
<div
|
|
153
|
+
style={{
|
|
154
|
+
display: "flex",
|
|
155
|
+
justifyContent: "center",
|
|
156
|
+
alignItems: "center",
|
|
157
|
+
overflow: "hidden",
|
|
158
|
+
height: 100,
|
|
159
|
+
width: 100,
|
|
160
|
+
backgroundImage: `url(${file.preview})`,
|
|
161
|
+
backgroundSize: "cover",
|
|
162
|
+
backgroundPosition: "center",
|
|
163
|
+
border: "1px solid black"
|
|
164
|
+
}}
|
|
165
|
+
key={file.name}
|
|
166
|
+
/>
|
|
121
167
|
</div>
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const thumbs = files.map((file, index) => (
|
|
126
|
-
<Badge
|
|
127
|
-
key={index}
|
|
128
|
-
onClick={(e) => {
|
|
129
|
-
e.preventDefault();
|
|
130
|
-
e.stopPropagation();
|
|
131
|
-
console.log("Clicking", index);
|
|
132
|
-
handleRemoveFile(index);
|
|
133
|
-
}}
|
|
134
|
-
badgeContent={<CloseIcon fontSize="small" />}
|
|
135
|
-
color="primary"
|
|
136
|
-
style={{
|
|
137
|
-
margin: 10,
|
|
138
|
-
width: 100,
|
|
139
|
-
height: 100
|
|
140
|
-
}}
|
|
141
|
-
>
|
|
142
|
-
<div
|
|
143
|
-
style={{
|
|
144
|
-
display: "flex",
|
|
145
|
-
justifyContent: "center",
|
|
146
|
-
alignItems: "center",
|
|
147
|
-
overflow: "hidden",
|
|
148
|
-
height: 100,
|
|
149
|
-
width: 100,
|
|
150
|
-
backgroundImage: `url(${file.preview})`,
|
|
151
|
-
backgroundSize: "cover",
|
|
152
|
-
backgroundPosition: "center"
|
|
153
|
-
}}
|
|
154
|
-
key={file.name}
|
|
155
|
-
/>
|
|
156
|
-
</Badge>
|
|
157
|
-
));
|
|
168
|
+
));
|
|
158
169
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
return (
|
|
171
|
+
<Container
|
|
172
|
+
variant="drop-area"
|
|
162
173
|
{...getRootProps({
|
|
163
|
-
|
|
164
|
-
console.log("e : ", e);
|
|
165
|
-
e.preventDefault(), console.log("khobza");
|
|
166
|
-
},
|
|
167
|
-
style: { height: "100%", width: "100%", padding: 10 }
|
|
174
|
+
style: { backgroundColor: isDragActive && "white" }
|
|
168
175
|
})}
|
|
169
176
|
>
|
|
170
177
|
<input {...getInputProps()} />
|
|
171
|
-
<
|
|
172
|
-
<
|
|
178
|
+
<Typography>Click here or drop files here to upload</Typography>
|
|
179
|
+
<Typography>Max file size is 5MB</Typography>
|
|
173
180
|
{thumbs ? <aside style={thumbsContainer}>{thumbs}</aside> : null}
|
|
174
|
-
{
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
{fileRejections[0]?.errors[0]?.code !== "too-many-files" ? (
|
|
182
|
+
// <Typography variant="">{texts.tooManyFiles}</Typography>
|
|
183
|
+
<HawaAlert text={texts.tooManyFiles} severity="error" />
|
|
184
|
+
) : (
|
|
185
|
+
errs
|
|
186
|
+
)}
|
|
187
|
+
</Container>
|
|
188
|
+
);
|
|
189
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MoreVert } from "@mui/icons-material";
|
|
2
|
+
import { Container, Stack } from "@mui/material";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
export const DraggableCard = (props) => {
|
|
6
|
+
return (
|
|
7
|
+
<Stack
|
|
8
|
+
variant="card"
|
|
9
|
+
direction="row"
|
|
10
|
+
maxWidth={props.maxWidth}
|
|
11
|
+
style={{ paddingLeft: 5 }}
|
|
12
|
+
>
|
|
13
|
+
<div
|
|
14
|
+
style={{
|
|
15
|
+
// backgroundColor: "blue",
|
|
16
|
+
display: "flex",
|
|
17
|
+
alignItems: "center",
|
|
18
|
+
// paddingRight: 5,
|
|
19
|
+
borderRight: "1px solid grey",
|
|
20
|
+
marginRight: 20
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
<MoreVert />
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div
|
|
27
|
+
style={{
|
|
28
|
+
// backgroundColor: "red",
|
|
29
|
+
width: "100%"
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
{props.children}
|
|
33
|
+
</div>
|
|
34
|
+
</Stack>
|
|
35
|
+
);
|
|
36
|
+
};
|
package/src/elements/index.js
CHANGED
|
@@ -345,4 +345,4 @@
|
|
|
345
345
|
|
|
346
346
|
|
|
347
347
|
|
|
348
|
-
window['STORIES'] = [{"titlePrefix":"","directory":"./src","files":"**/*.stories.mdx","importPathMatcher":"^\\.[\\\\/](?:src(?:[\\\\/](?!\\.)(?:(?:(?!(?:^|[\\\\/])\\.).)*?)[\\\\/]|[\\\\/]|$)(?!\\.)(?=.)[^\\\\/]*?\\.stories\\.mdx)$"},{"titlePrefix":"","directory":"./src","files":"**/*.stories.@(js|jsx|ts|tsx)","importPathMatcher":"^\\.[\\\\/](?:src(?:[\\\\/](?!\\.)(?:(?:(?!(?:^|[\\\\/])\\.).)*?)[\\\\/]|[\\\\/]|$)(?!\\.)(?=.)[^\\\\/]*?\\.stories\\.(js|jsx|ts|tsx))$"}];</script><script src="runtime~main.708d7ac1.iframe.bundle.js"></script><script src="vendors~main.
|
|
348
|
+
window['STORIES'] = [{"titlePrefix":"","directory":"./src","files":"**/*.stories.mdx","importPathMatcher":"^\\.[\\\\/](?:src(?:[\\\\/](?!\\.)(?:(?:(?!(?:^|[\\\\/])\\.).)*?)[\\\\/]|[\\\\/]|$)(?!\\.)(?=.)[^\\\\/]*?\\.stories\\.mdx)$"},{"titlePrefix":"","directory":"./src","files":"**/*.stories.@(js|jsx|ts|tsx)","importPathMatcher":"^\\.[\\\\/](?:src(?:[\\\\/](?!\\.)(?:(?:(?!(?:^|[\\\\/])\\.).)*?)[\\\\/]|[\\\\/]|$)(?!\\.)(?=.)[^\\\\/]*?\\.stories\\.(js|jsx|ts|tsx))$"}];</script><script src="runtime~main.708d7ac1.iframe.bundle.js"></script><script src="vendors~main.07e1611f.iframe.bundle.js"></script><script src="main.6eab4ef6.iframe.bundle.js"></script></body></html>
|
|
@@ -56,4 +56,4 @@
|
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
window['DOCS_MODE'] = false;</script><script src="runtime~main.c8dac23bc753439736f0.manager.bundle.js"></script><script src="vendors~main.
|
|
59
|
+
window['DOCS_MODE'] = false;</script><script src="runtime~main.c8dac23bc753439736f0.manager.bundle.js"></script><script src="vendors~main.11281b487bf96f5ff19e.manager.bundle.js"></script><script src="main.9d5968bcf15d21f5487c.manager.bundle.js"></script></body></html>
|