@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.
@@ -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 styles from "../styles/Theme.module.css";
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 DragDropItemImage = ({
17
+ export const DragDropImages = ({
18
+ texts,
18
19
  files,
19
20
  setFiles,
20
21
  itemId,
21
22
  setDeletedFiles,
22
- refetchSingleMenu
23
- }) => {
24
- const token = getToken();
25
- const [cmp, setCmp] = useState(0);
26
- //const [thumbs, setThumbs] = useState("");
27
- const { t } = useTranslation("common");
28
- const { getRootProps, getInputProps, fileRejections, acceptedFiles } =
29
- useDropzone({
30
- multiple: token.Pack?.image_per_item_limit > 1,
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: token.Pack?.image_per_item_limit,
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
- const handleRemoveFile = async (file) => {
45
- console.log("fezafezaf", acceptedFiles[file]);
46
- if (acceptedFiles[file]?.isFromDB) {
47
- setDeletedFiles((old) => [
48
- ...old,
49
- {
50
- img_url: acceptedFiles[file]?.img_url,
51
- _id: acceptedFiles[file]?._id
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
- try {
55
- // await axios.post(
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
- console.log("accepted files after delete : ", acceptedFiles);
74
- setCmp((old) => old + 1);
75
- return;
76
- }
77
- // if (file.hasOwnProperty("_id")) {
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
- setFiles(
84
- acceptedFiles.map((f) =>
85
- Object.assign(f, { preview: URL.createObjectURL(f) })
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
- // setFiles(acceptedFiles);
89
- };
90
- useEffect(
91
- () => () => {
92
- files.forEach((file) => {
93
- URL.revokeObjectURL(file.preview);
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
- console.log("accepted files : ", acceptedFiles);
110
- setFiles(acceptedFiles);
111
- }
112
- return () => {
113
- acceptedFiles.splice(0, acceptedFiles?.length);
114
- };
115
- }, []);
116
- const errs = fileRejections.map((rej, i) => {
117
- return (
118
- <div key={i} className={styles.upload_error_container}>
119
- <div>{rej.file.name}</div>
120
- <div>{t(rej.errors[0].code)}</div>
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
- return (
160
- <section className={styles.upload_main_container}>
161
- <div
170
+ return (
171
+ <Container
172
+ variant="drop-area"
162
173
  {...getRootProps({
163
- onClick: (e) => {
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
- <div style={{ fontSize: 13 }}>{t("drag-n-drop")}</div>
172
- <div style={{ fontSize: 13, marginTop: 5 }}>{t("max-file-size")}</div>
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
- {errs}
175
- </div>
176
- </section>
177
- );
178
- };
179
-
180
- export default DragDropItemImage;
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
+ };
@@ -19,3 +19,5 @@ export * from "./HawaTable";
19
19
  export * from "./HawaColorPicker";
20
20
  export * from "./HawaSearchBar";
21
21
  export * from "./HawaAccordian";
22
+ export * from "./DragDropImages";
23
+ export * from "./DraggableCard";
@@ -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.a7262b49.iframe.bundle.js"></script><script src="main.e9b7f5c4.iframe.bundle.js"></script></body></html>
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.a697e07137d366f95f76.manager.bundle.js"></script><script src="main.9d5968bcf15d21f5487c.manager.bundle.js"></script></body></html>
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>