@sikka/hawa 0.0.2 → 0.0.5

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.
Files changed (192) hide show
  1. package/.github/workflows/hawa-publish-push.yml +45 -0
  2. package/.github/workflows/hawa-publish.yml +45 -0
  3. package/.prettierrc +28 -28
  4. package/README.md +149 -148
  5. package/es/index.es.js +1 -0
  6. package/lib/index.js +1 -0
  7. package/package.json +62 -47
  8. package/rollup.config.js +30 -30
  9. package/src/Assets/images/card-background/1.jpeg +0 -0
  10. package/src/Assets/images/card-background/10.jpeg +0 -0
  11. package/src/Assets/images/card-background/11.jpeg +0 -0
  12. package/src/Assets/images/card-background/12.jpeg +0 -0
  13. package/src/Assets/images/card-background/13.jpeg +0 -0
  14. package/src/Assets/images/card-background/14.jpeg +0 -0
  15. package/src/Assets/images/card-background/15.jpeg +0 -0
  16. package/src/Assets/images/card-background/16.jpeg +0 -0
  17. package/src/Assets/images/card-background/17.jpeg +0 -0
  18. package/src/Assets/images/card-background/18.jpeg +0 -0
  19. package/src/Assets/images/card-background/19.jpeg +0 -0
  20. package/src/Assets/images/card-background/2.jpeg +0 -0
  21. package/src/Assets/images/card-background/20.jpeg +0 -0
  22. package/src/Assets/images/card-background/21.jpeg +0 -0
  23. package/src/Assets/images/card-background/22.jpeg +0 -0
  24. package/src/Assets/images/card-background/23.jpeg +0 -0
  25. package/src/Assets/images/card-background/24.jpeg +0 -0
  26. package/src/Assets/images/card-background/25.jpeg +0 -0
  27. package/src/Assets/images/card-background/3.jpeg +0 -0
  28. package/src/Assets/images/card-background/4.jpeg +0 -0
  29. package/src/Assets/images/card-background/5.jpeg +0 -0
  30. package/src/Assets/images/card-background/6.jpeg +0 -0
  31. package/src/Assets/images/card-background/7.jpeg +0 -0
  32. package/src/Assets/images/card-background/8.jpeg +0 -0
  33. package/src/Assets/images/card-background/9.jpeg +0 -0
  34. package/src/Assets/images/card-type/amex.png +0 -0
  35. package/src/Assets/images/card-type/diners.png +0 -0
  36. package/src/Assets/images/card-type/discover.png +0 -0
  37. package/src/Assets/images/card-type/mastercard.png +0 -0
  38. package/src/Assets/images/card-type/troy.png +0 -0
  39. package/src/Assets/images/card-type/unionpay.png +0 -0
  40. package/src/Assets/images/card-type/visa.png +0 -0
  41. package/src/blocks/Account/UserProfile.js +15 -0
  42. package/src/blocks/Account/UserSettings.js +15 -0
  43. package/src/blocks/Account/index.js +2 -0
  44. package/src/blocks/AuthForms/NewPasswordForm.js +24 -0
  45. package/src/blocks/AuthForms/ResetPasswordForm.js +13 -0
  46. package/src/blocks/AuthForms/SignInForm.js +55 -0
  47. package/src/blocks/AuthForms/SignUpForm.js +68 -0
  48. package/src/{components/Hawa → blocks}/AuthForms/index.js +4 -4
  49. package/src/blocks/Payment/CreditCardForm.js +31 -0
  50. package/src/blocks/Payment/Form/CForm.js +328 -0
  51. package/src/blocks/Payment/Form/Card.js +242 -0
  52. package/src/blocks/Payment/Gateway/GooglePay.js +251 -0
  53. package/src/blocks/Payment/Gateway/Payfort.js +90 -0
  54. package/src/blocks/Payment/Gateway/Paypal.js +138 -0
  55. package/src/blocks/Payment/Gateway/Wallet.js +149 -0
  56. package/src/blocks/Payment/PaymentMethod.js +132 -0
  57. package/src/blocks/Payment/SelectPayment.js +95 -0
  58. package/src/blocks/Payment/index.js +16 -0
  59. package/src/index.js +4 -1
  60. package/src/layout/Box.js +39 -0
  61. package/src/layout/index.js +1 -0
  62. package/src/stories/ActionButton.stories.js +53 -0
  63. package/src/stories/AdaptiveButton.stories.js +80 -80
  64. package/src/stories/Alert.stories.js +41 -48
  65. package/src/stories/BlocksStories/AuthForm.stories.js +99 -0
  66. package/src/stories/BlocksStories/PaymentForm.stories.js +111 -0
  67. package/src/stories/BlocksStories/UserAccount.stories.js +46 -0
  68. package/src/stories/CheckBox.stories.js +35 -34
  69. package/src/stories/GlobalVariables.stories.js +44 -108
  70. package/src/stories/HawaProvider.stories.js +22 -23
  71. package/src/stories/InputLabel.stories.js +92 -100
  72. package/src/stories/Introduction.stories.js +211 -0
  73. package/src/stories/LayoutStories/Box.stories.js +56 -0
  74. package/src/stories/RadioSelector.stories.js +69 -69
  75. package/src/stories/TextField.stories.js +50 -50
  76. package/src/styles.css +400 -400
  77. package/src/styles.scss +679 -0
  78. package/src/themes/HawaProvider.js +87 -0
  79. package/src/ui/ActionButton.js +40 -0
  80. package/src/{components/Hawa/AdaptiveButton → ui}/AdaptiveButton.js +252 -254
  81. package/src/ui/ApplePayButton.js +94 -0
  82. package/src/{components/Hawa/AutoCompleteField/AutoCompleteField.jsx → ui/AutoCompleteField.js} +32 -33
  83. package/src/{components/Hawa/Checkbox/Checkbox.jsx → ui/Checkbox.js} +21 -20
  84. package/src/{components/Hawa/DragDropImages/DragDropImages.jsx → ui/DragDropImages.js} +180 -180
  85. package/src/ui/GithubButton.js +91 -0
  86. package/src/ui/GoogleButton.js +83 -0
  87. package/src/ui/GooglePayButton.js +94 -0
  88. package/src/{components/Hawa/Hawa.jsx → ui/Hawa.js} +3 -3
  89. package/src/ui/HawaInputLabel.js +33 -0
  90. package/src/{components/Hawa/TextArea/TextArea.jsx → ui/HawaTextArea.js} +38 -38
  91. package/src/ui/HawaTextField.js +118 -0
  92. package/src/ui/MadaButton.js +94 -0
  93. package/src/ui/PayPalButton.js +94 -0
  94. package/src/{components/Hawa/RadioBox/RadioBox.jsx → ui/RadioBox.js} +29 -29
  95. package/src/{components/Hawa/RadioSelector/RadioSelector.jsx → ui/RadioSelector.js} +51 -51
  96. package/src/{components/Hawa/Row/Row.jsx → ui/Row.js} +21 -21
  97. package/src/ui/STCPayButton.js +94 -0
  98. package/src/{components/Hawa/SelectedField/SelectedField.jsx → ui/SelectedField.js} +46 -46
  99. package/src/ui/StyledAlert.js +30 -0
  100. package/src/{components/Hawa/StyledTooltip → ui}/StyledTooltip.js +46 -46
  101. package/src/{components/Hawa/TabPanel/TabPanel.jsx → ui/TabPanel.js} +37 -37
  102. package/src/ui/TwitterButton.js +84 -0
  103. package/src/ui/VisaMasterButton.js +94 -0
  104. package/src/ui/WalletButton.js +91 -0
  105. package/src/ui/index.js +22 -0
  106. package/src/util.js +20 -20
  107. package/storybook-static/0.54f7e52e.iframe.bundle.js +1 -0
  108. package/storybook-static/0.f47eb24a4893a96ec307.manager.bundle.js +1 -0
  109. package/storybook-static/1.95be85dd.iframe.bundle.js +3 -0
  110. package/storybook-static/{1.7c0dc86d.iframe.bundle.js.LICENSE.txt → 1.95be85dd.iframe.bundle.js.LICENSE.txt} +0 -0
  111. package/storybook-static/1.95be85dd.iframe.bundle.js.map +1 -0
  112. package/storybook-static/2.eb601582.iframe.bundle.js +1 -0
  113. package/storybook-static/{3.592ce28f.iframe.bundle.js → 3.d72f7fac.iframe.bundle.js} +0 -0
  114. package/storybook-static/4.0fcda1281dc1961dbe94.manager.bundle.js +2 -0
  115. package/storybook-static/{5.f459d151315e6780c20f.manager.bundle.js.LICENSE.txt → 4.0fcda1281dc1961dbe94.manager.bundle.js.LICENSE.txt} +0 -0
  116. package/storybook-static/5.63ab4f94d50a3acf080d.manager.bundle.js +1 -0
  117. package/storybook-static/6.a6d45262f7e98f3f18d3.manager.bundle.js +2 -0
  118. package/storybook-static/{11.f4e922583ae35da460f3.manager.bundle.js.LICENSE.txt → 6.a6d45262f7e98f3f18d3.manager.bundle.js.LICENSE.txt} +0 -0
  119. package/storybook-static/{7.3d04765dbf3f1dcd706c.manager.bundle.js → 7.097710753af9a1c41b80.manager.bundle.js} +1 -1
  120. package/storybook-static/7.ffb0d84b.iframe.bundle.js +1 -0
  121. package/storybook-static/{8.8e2132ec.iframe.bundle.js → 8.68cd1217.iframe.bundle.js} +2 -2
  122. package/storybook-static/{8.8e2132ec.iframe.bundle.js.LICENSE.txt → 8.68cd1217.iframe.bundle.js.LICENSE.txt} +0 -0
  123. package/storybook-static/8.68cd1217.iframe.bundle.js.map +1 -0
  124. package/storybook-static/8.76c3cbf398692028e834.manager.bundle.js +1 -0
  125. package/storybook-static/{9.109ea555.iframe.bundle.js → 9.488e3969.iframe.bundle.js} +0 -0
  126. package/storybook-static/iframe.html +2 -2
  127. package/storybook-static/index.html +9 -1
  128. package/storybook-static/main.044648aa.iframe.bundle.js +1 -0
  129. package/storybook-static/main.ac6e4b72b033097dad76.manager.bundle.js +1 -0
  130. package/storybook-static/{runtime~main.ffc8677e.iframe.bundle.js → runtime~main.3e280e98.iframe.bundle.js} +1 -1
  131. package/storybook-static/runtime~main.c8dac23bc753439736f0.manager.bundle.js +1 -0
  132. package/storybook-static/vendors~main.a697e07137d366f95f76.manager.bundle.js +2 -0
  133. package/storybook-static/{vendors~main.a935f15a2179a6eff5fd.manager.bundle.js.LICENSE.txt → vendors~main.a697e07137d366f95f76.manager.bundle.js.LICENSE.txt} +6 -12
  134. package/storybook-static/vendors~main.d75dc38b.iframe.bundle.js +76 -0
  135. package/storybook-static/{vendors~main.4aa936b1.iframe.bundle.js.LICENSE.txt → vendors~main.d75dc38b.iframe.bundle.js.LICENSE.txt} +3 -45
  136. package/storybook-static/vendors~main.d75dc38b.iframe.bundle.js.map +1 -0
  137. package/tools/build-styles.js +17 -0
  138. package/dist/index.es.js +0 -37
  139. package/dist/index.js +0 -37
  140. package/src/components/Hawa/AdaptiveButton/index.js +0 -1
  141. package/src/components/Hawa/AuthForms/NewPasswordForm.js +0 -23
  142. package/src/components/Hawa/AuthForms/ResetPasswordForm.js +0 -21
  143. package/src/components/Hawa/AuthForms/SignInForm.js +0 -25
  144. package/src/components/Hawa/AuthForms/SignUpForm.js +0 -26
  145. package/src/components/Hawa/AuthForms/viaFacebook.js +0 -0
  146. package/src/components/Hawa/AuthForms/viaGithub.js +0 -0
  147. package/src/components/Hawa/AuthForms/viaGoogle.js +0 -0
  148. package/src/components/Hawa/AuthForms/viaTwitter.js +0 -0
  149. package/src/components/Hawa/AutoCompleteField/index.js +0 -1
  150. package/src/components/Hawa/Box/Box.js +0 -18
  151. package/src/components/Hawa/Box/index.js +0 -1
  152. package/src/components/Hawa/Checkbox/index.js +0 -1
  153. package/src/components/Hawa/DragDropImages/index.js +0 -1
  154. package/src/components/Hawa/HawaProvider/HawaProvider.js +0 -19
  155. package/src/components/Hawa/HawaProvider/index.js +0 -1
  156. package/src/components/Hawa/InputLabel/StyledInputLabel.js +0 -15
  157. package/src/components/Hawa/InputLabel/index.js +0 -1
  158. package/src/components/Hawa/RadioBox/index.js +0 -1
  159. package/src/components/Hawa/RadioSelector/index.js +0 -1
  160. package/src/components/Hawa/Row/index.js +0 -1
  161. package/src/components/Hawa/SelectedField/index.js +0 -1
  162. package/src/components/Hawa/StyledAlert/StyledAlert.js +0 -15
  163. package/src/components/Hawa/StyledAlert/index.js +0 -1
  164. package/src/components/Hawa/StyledTooltip/index.js +0 -1
  165. package/src/components/Hawa/TabPanel/index.js +0 -1
  166. package/src/components/Hawa/TextArea/index.js +0 -1
  167. package/src/components/Hawa/TextField/TextField.js +0 -54
  168. package/src/components/Hawa/TextField/index.js +0 -1
  169. package/src/components/Hawa/index.js +0 -10
  170. package/src/stories/AuthForm.stories.js +0 -76
  171. package/src/stories/Box.stories.js +0 -45
  172. package/storybook-static/0.12392f0b.iframe.bundle.js +0 -1
  173. package/storybook-static/0.55b012452099ace2dca6.manager.bundle.js +0 -1
  174. package/storybook-static/1.0f38715c61c7c3cd11db.manager.bundle.js +0 -1
  175. package/storybook-static/1.7c0dc86d.iframe.bundle.js +0 -3
  176. package/storybook-static/1.7c0dc86d.iframe.bundle.js.map +0 -1
  177. package/storybook-static/10.9f2923a7561bc20fffdb.manager.bundle.js +0 -1
  178. package/storybook-static/11.f4e922583ae35da460f3.manager.bundle.js +0 -2
  179. package/storybook-static/12.1415460941f0bdcb8fa8.manager.bundle.js +0 -1
  180. package/storybook-static/2.ee357266.iframe.bundle.js +0 -1
  181. package/storybook-static/5.f459d151315e6780c20f.manager.bundle.js +0 -2
  182. package/storybook-static/6.3bd64d820f3745f262ff.manager.bundle.js +0 -1
  183. package/storybook-static/7.af56919f.iframe.bundle.js +0 -1
  184. package/storybook-static/8.8e2132ec.iframe.bundle.js.map +0 -1
  185. package/storybook-static/8.b541eadfcb9164835dfc.manager.bundle.js +0 -1
  186. package/storybook-static/9.411ac8e451bbb10926c7.manager.bundle.js +0 -1
  187. package/storybook-static/main.78b7d418.iframe.bundle.js +0 -1
  188. package/storybook-static/main.9bb085ebb152f5b19a2a.manager.bundle.js +0 -1
  189. package/storybook-static/runtime~main.9468098d21070636985f.manager.bundle.js +0 -1
  190. package/storybook-static/vendors~main.4aa936b1.iframe.bundle.js +0 -3
  191. package/storybook-static/vendors~main.4aa936b1.iframe.bundle.js.map +0 -1
  192. package/storybook-static/vendors~main.a935f15a2179a6eff5fd.manager.bundle.js +0 -2
@@ -0,0 +1,94 @@
1
+ import React, { useContext } from "react";
2
+ import { ThemeProvider } from "../themes/HawaProvider";
3
+ import Button from "@mui/material/Button";
4
+ import { styled, darken } from "@mui/material/styles";
5
+
6
+ import GitHubIcon from "@mui/icons-material/GitHub";
7
+
8
+ export const ApplePayButton = (props) => {
9
+ const theme = useContext(ThemeProvider);
10
+ let buttonStyle = {};
11
+
12
+ console.log(Object.keys(theme.actionButton));
13
+ let currentTheme = Object.keys(theme.actionButton).find(
14
+ (themeName) => themeName.toLowerCase() === props.themeType?.toLowerCase()
15
+ );
16
+ if (currentTheme) {
17
+ buttonStyle = {
18
+ cursor: "pointer",
19
+ display: "flex",
20
+ flexDirection: "row",
21
+ alignItems: "center",
22
+ justifyContent: "center",
23
+ padding: 0,
24
+ marginTop: theme.actionButton[currentTheme].margin,
25
+ border: props.outlined ? "2px solid black" : "none",
26
+ borderRadius: theme.actionButton[currentTheme].borderRadius,
27
+ backgroundColor: "white",
28
+ "&:hover": {
29
+ backgroundColor: darken("#ffffff", 0.1)
30
+ }
31
+ };
32
+ } else {
33
+ buttonStyle = {
34
+ cursor: "pointer",
35
+ display: "flex",
36
+ flexDirection: "row",
37
+ alignItems: "center",
38
+ justifyContent: "center",
39
+ marginTop: theme.margins,
40
+ border: props.outlined ? "2px solid black" : "none",
41
+ borderRadius: 0,
42
+ backgroundColor: "white",
43
+ "&:hover": {
44
+ backgroundColor: darken("#ffffff", 0.1)
45
+ }
46
+ };
47
+ }
48
+
49
+ const StyledButton = styled(Button)(({ theme }) => {
50
+ return {
51
+ // "label + &": {
52
+ // marginTop: theme.spacing(3)
53
+ // },
54
+
55
+ borderRadius: 4,
56
+ position: "relative",
57
+ border: "1px solid #ced4da",
58
+ fontSize: 16,
59
+ // width: "auto",
60
+ height: 50,
61
+ // padding: "10px 12px",
62
+ ...buttonStyle,
63
+ "&:focus": {
64
+ // boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 0.2rem`,
65
+ borderColor: theme.palette.primary.main
66
+ }
67
+ };
68
+ });
69
+
70
+ return (
71
+ <StyledButton
72
+ // style={buttonStyle}
73
+ onClick={props.handleClick}
74
+ >
75
+ <img
76
+ src="https://sikka-images.s3.ap-southeast-1.amazonaws.com/payments/apple-pay.png"
77
+ height={40}
78
+ />{" "}
79
+ <div style={{ width: 10 }} />
80
+ <p
81
+ style={{
82
+ color: "black",
83
+ fontSize: 14,
84
+ textAlign: "center",
85
+ letterSpacing: 0.4,
86
+ fontFamily: "Roboto",
87
+ fontWeight: 500
88
+ }}
89
+ >
90
+ {props.buttonText}
91
+ </p>
92
+ </StyledButton>
93
+ );
94
+ };
@@ -1,33 +1,32 @@
1
- import React from "react";
2
- import { Controller, useFormContext } from "react-hook-form";
3
- // import Autocomplete from "@material-ui/lab/Autocomplete";
4
-
5
- export const AutoCompleteField = (props) => {
6
- const { control } = useFormContext();
7
- const { name, rules, shouldUnregister } = props;
8
-
9
- return (
10
- <React.Fragment>
11
- <Controller
12
- name={name}
13
- rules={rules}
14
- control={control}
15
- shouldUnregister={shouldUnregister}
16
- className="theme_form_input"
17
- render={({ field: { onChange, value } }) => {
18
- return (
19
- <input type="text" />
20
- // <Autocomplete
21
- // onChange={(e, data) => {
22
- // onChange(data);
23
- // }}
24
- // value={value ?? ""}
25
- // {...props}
26
- // className={"theme_form_input"}
27
- // />
28
- );
29
- }}
30
- />
31
- </React.Fragment>
32
- );
33
- };
1
+ import React from "react";
2
+ import { Controller, useFormContext } from "react-hook-form";
3
+
4
+ export const AutoCompleteField = (props) => {
5
+ const { control } = useFormContext();
6
+ const { name, rules, shouldUnregister } = props;
7
+
8
+ return (
9
+ <React.Fragment>
10
+ <Controller
11
+ name={name}
12
+ rules={rules}
13
+ control={control}
14
+ shouldUnregister={shouldUnregister}
15
+ className="theme_form_input"
16
+ render={({ field: { onChange, value } }) => {
17
+ return (
18
+ <input type="text" />
19
+ // <Autocomplete
20
+ // onChange={(e, data) => {
21
+ // onChange(data);
22
+ // }}
23
+ // value={value ?? ""}
24
+ // {...props}
25
+ // className={"theme_form_input"}
26
+ // />
27
+ );
28
+ }}
29
+ />
30
+ </React.Fragment>
31
+ );
32
+ };
@@ -1,20 +1,21 @@
1
- import React from "react";
2
- import FormControlLabel from "@material-ui/core/FormControlLabel";
3
- import Checkbox from "@material-ui/core/Checkbox";
4
- import PropTypes from "prop-types";
5
-
6
- export const StyledCheckbox = (props) => {
7
- console.log("props : ", props);
8
- return (
9
- <React.Fragment>
10
- <FormControlLabel
11
- control={
12
- <Checkbox
13
- style={{ color: props.color || null }}
14
- defaultChecked={props.defaultValue}
15
- />
16
- }
17
- />
18
- </React.Fragment>
19
- );
20
- };
1
+ import React from "react";
2
+ import FormControlLabel from "@mui/material/FormControlLabel";
3
+ import Checkbox from "@mui/material/Checkbox";
4
+ // import PropTypes from "prop-types";
5
+
6
+ export const StyledCheckbox = (props) => {
7
+ console.log("props : ", props);
8
+ return (
9
+ <React.Fragment>
10
+ <FormControlLabel
11
+ label={props.label}
12
+ control={
13
+ <Checkbox
14
+ style={{ color: props.color || null }}
15
+ defaultChecked={props.defaultValue}
16
+ />
17
+ }
18
+ />
19
+ </React.Fragment>
20
+ );
21
+ };
@@ -1,180 +1,180 @@
1
- import React, { useEffect, useState } from "react";
2
- // import axios from "axios";
3
- import { getToken } from "../token";
4
- import { useDropzone } from "react-dropzone";
5
- import useTranslation from "next-translate/useTranslation";
6
- import Badge from "@material-ui/core/Badge";
7
- import CloseIcon from "@material-ui/icons/Close";
8
- import styles from "../styles/Theme.module.css";
9
-
10
- const thumbsContainer = {
11
- display: "flex",
12
- flexDirection: "row",
13
- flexWrap: "wrap",
14
- marginTop: 10
15
- };
16
-
17
- const DragDropItemImage = ({
18
- files,
19
- setFiles,
20
- itemId,
21
- 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,
31
- accept: "image/*",
32
- maxSize: 5000000,
33
- maxFiles: token.Pack?.image_per_item_limit,
34
- onDrop: (acceptedFiles) => {
35
- setFiles(
36
- acceptedFiles.map((file, index) =>
37
- Object.assign(file, {
38
- preview: URL.createObjectURL(file)
39
- })
40
- )
41
- );
42
- }
43
- });
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
- }
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);
72
- }
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);
82
-
83
- setFiles(
84
- acceptedFiles.map((f) =>
85
- Object.assign(f, { preview: URL.createObjectURL(f) })
86
- )
87
- );
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
107
- });
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>
121
- </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
- ));
158
-
159
- return (
160
- <section className={styles.upload_main_container}>
161
- <div
162
- {...getRootProps({
163
- onClick: (e) => {
164
- console.log("e : ", e);
165
- e.preventDefault(), console.log("khobza");
166
- },
167
- style: { height: "100%", width: "100%", padding: 10 }
168
- })}
169
- >
170
- <input {...getInputProps()} />
171
- <div style={{ fontSize: 13 }}>{t("drag-n-drop")}</div>
172
- <div style={{ fontSize: 13, marginTop: 5 }}>{t("max-file-size")}</div>
173
- {thumbs ? <aside style={thumbsContainer}>{thumbs}</aside> : null}
174
- {errs}
175
- </div>
176
- </section>
177
- );
178
- };
179
-
180
- export default DragDropItemImage;
1
+ import React, { useEffect, useState } from "react";
2
+ // import axios from "axios";
3
+ import { getToken } from "../token";
4
+ import { useDropzone } from "react-dropzone";
5
+ import useTranslation from "next-translate/useTranslation";
6
+ import Badge from "@mui/material/Badge";
7
+ import CloseIcon from "@mui/icons-material/Close";
8
+ import styles from "../styles/Theme.module.css";
9
+
10
+ const thumbsContainer = {
11
+ display: "flex",
12
+ flexDirection: "row",
13
+ flexWrap: "wrap",
14
+ marginTop: 10
15
+ };
16
+
17
+ const DragDropItemImage = ({
18
+ files,
19
+ setFiles,
20
+ itemId,
21
+ 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,
31
+ accept: "image/*",
32
+ maxSize: 5000000,
33
+ maxFiles: token.Pack?.image_per_item_limit,
34
+ onDrop: (acceptedFiles) => {
35
+ setFiles(
36
+ acceptedFiles.map((file, index) =>
37
+ Object.assign(file, {
38
+ preview: URL.createObjectURL(file)
39
+ })
40
+ )
41
+ );
42
+ }
43
+ });
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
+ }
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);
72
+ }
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);
82
+
83
+ setFiles(
84
+ acceptedFiles.map((f) =>
85
+ Object.assign(f, { preview: URL.createObjectURL(f) })
86
+ )
87
+ );
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
107
+ });
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>
121
+ </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
+ ));
158
+
159
+ return (
160
+ <section className={styles.upload_main_container}>
161
+ <div
162
+ {...getRootProps({
163
+ onClick: (e) => {
164
+ console.log("e : ", e);
165
+ e.preventDefault(), console.log("khobza");
166
+ },
167
+ style: { height: "100%", width: "100%", padding: 10 }
168
+ })}
169
+ >
170
+ <input {...getInputProps()} />
171
+ <div style={{ fontSize: 13 }}>{t("drag-n-drop")}</div>
172
+ <div style={{ fontSize: 13, marginTop: 5 }}>{t("max-file-size")}</div>
173
+ {thumbs ? <aside style={thumbsContainer}>{thumbs}</aside> : null}
174
+ {errs}
175
+ </div>
176
+ </section>
177
+ );
178
+ };
179
+
180
+ export default DragDropItemImage;
@@ -0,0 +1,91 @@
1
+ import React, { useContext } from "react";
2
+ import { ThemeProvider } from "../themes/HawaProvider";
3
+ import Button from "@mui/material/Button";
4
+ import { styled, darken } from "@mui/material/styles";
5
+
6
+ import GitHubIcon from "@mui/icons-material/GitHub";
7
+
8
+ export const GithubButton = (props) => {
9
+ const theme = useContext(ThemeProvider);
10
+ let buttonStyle = {};
11
+
12
+ console.log(Object.keys(theme.actionButton));
13
+ let currentTheme = Object.keys(theme.actionButton).find(
14
+ (themeName) => themeName.toLowerCase() === props.themeType?.toLowerCase()
15
+ );
16
+ if (currentTheme) {
17
+ buttonStyle = {
18
+ cursor: "pointer",
19
+ display: "flex",
20
+ flexDirection: "row",
21
+ alignItems: "center",
22
+ justifyContent: "center",
23
+ padding: 0,
24
+ marginTop: theme.actionButton[currentTheme].margin,
25
+ border: props.outlined ? "2px solid black" : "none",
26
+ borderRadius: theme.actionButton[currentTheme].borderRadius,
27
+ backgroundColor: "white",
28
+ "&:hover": {
29
+ backgroundColor: darken("#ffffff", 0.1)
30
+ }
31
+ };
32
+ } else {
33
+ buttonStyle = {
34
+ cursor: "pointer",
35
+ display: "flex",
36
+ flexDirection: "row",
37
+ alignItems: "center",
38
+ justifyContent: "center",
39
+ marginTop: theme.margins,
40
+ border: props.outlined ? "2px solid black" : "none",
41
+ borderRadius: 0,
42
+ backgroundColor: "white",
43
+ "&:hover": {
44
+ backgroundColor: darken("#ffffff", 0.1)
45
+ }
46
+ };
47
+ }
48
+
49
+ const StyledButton = styled(Button)(({ theme }) => {
50
+ return {
51
+ // "label + &": {
52
+ // marginTop: theme.spacing(3)
53
+ // },
54
+
55
+ borderRadius: 4,
56
+ position: "relative",
57
+ border: "1px solid #ced4da",
58
+ fontSize: 16,
59
+ // width: "auto",
60
+ height: 50,
61
+ // padding: "10px 12px",
62
+ ...buttonStyle,
63
+ "&:focus": {
64
+ // boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 0.2rem`,
65
+ borderColor: theme.palette.primary.main
66
+ }
67
+ };
68
+ });
69
+
70
+ return (
71
+ <StyledButton
72
+ // style={buttonStyle}
73
+ onClick={props.handleClick}
74
+ >
75
+ <GitHubIcon />
76
+ <div style={{ width: 10 }} />
77
+ <p
78
+ style={{
79
+ color: "black",
80
+ fontSize: 14,
81
+ textAlign: "center",
82
+ letterSpacing: 0.4,
83
+ fontFamily: "Roboto",
84
+ fontWeight: 500
85
+ }}
86
+ >
87
+ {props.buttonText}
88
+ </p>
89
+ </StyledButton>
90
+ );
91
+ };