@gnar-engine/cli 1.0.0 → 1.0.1

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 (230) hide show
  1. package/assets/gnar-engine-logo-white.svg +9 -0
  2. package/bootstrap/deploy.localdev.yml +51 -0
  3. package/bootstrap/secrets.localdev.yml +27 -0
  4. package/bootstrap/services/agent/Dockerfile +23 -0
  5. package/bootstrap/services/agent/notes.md +28 -0
  6. package/bootstrap/services/agent/package.json +16 -0
  7. package/bootstrap/services/agent/src/app.js +52 -0
  8. package/bootstrap/services/agent/src/commands/agent.handler.js +104 -0
  9. package/bootstrap/services/agent/src/config.js +52 -0
  10. package/bootstrap/services/agent/src/controllers/http.controller.js +44 -0
  11. package/bootstrap/services/agent/src/controllers/message.controller.js +51 -0
  12. package/bootstrap/services/agent/src/db/migrations/01-init.js +50 -0
  13. package/bootstrap/services/agent/src/db/migrations/02-agent-service-init.js +36 -0
  14. package/bootstrap/services/agent/src/policies/agent.policy.js +13 -0
  15. package/bootstrap/services/agent/src/schema/Agent.schema.js +17 -0
  16. package/bootstrap/services/agent/src/services/agent.service.js +259 -0
  17. package/bootstrap/services/agent/src/services/chatgpt.service.js +46 -0
  18. package/bootstrap/services/agent/src/services/manifest.service.js +21 -0
  19. package/bootstrap/services/control/Dockerfile +23 -0
  20. package/bootstrap/services/control/Dockerfile.prod +37 -0
  21. package/bootstrap/services/control/README.md +25 -0
  22. package/bootstrap/services/control/package.json +16 -0
  23. package/bootstrap/services/control/src/app.js +45 -0
  24. package/bootstrap/services/control/src/commands/control.handler.js +231 -0
  25. package/bootstrap/services/control/src/commands/service.handler.js +81 -0
  26. package/bootstrap/services/control/src/commands/task.handler.js +247 -0
  27. package/bootstrap/services/control/src/config.js +55 -0
  28. package/bootstrap/services/control/src/controllers/http.controller.js +228 -0
  29. package/bootstrap/services/control/src/controllers/message.controller.js +40 -0
  30. package/bootstrap/services/control/src/db/migrations/01-init.js +50 -0
  31. package/bootstrap/services/control/src/db/migrations/02-control-service-init.js +60 -0
  32. package/bootstrap/services/control/src/db/migrations/03-alter-tasks.js +29 -0
  33. package/bootstrap/services/control/src/policies/task.policy.js +53 -0
  34. package/bootstrap/services/control/src/schema/control.schema.js +42 -0
  35. package/bootstrap/services/control/src/services/registry.service.js +83 -0
  36. package/bootstrap/services/control/src/services/reset.service.js +28 -0
  37. package/bootstrap/services/control/src/services/task.service.js +153 -0
  38. package/bootstrap/services/control/src/tests/control.test.js +50 -0
  39. package/bootstrap/services/notification/Dockerfile +23 -0
  40. package/bootstrap/services/notification/Dockerfile.prod +37 -0
  41. package/bootstrap/services/notification/README.md +3 -0
  42. package/bootstrap/services/notification/package.json +34 -0
  43. package/bootstrap/services/notification/src/app.js +51 -0
  44. package/bootstrap/services/notification/src/commands/command-bus.js +20 -0
  45. package/bootstrap/services/notification/src/commands/handlers/control.handler.js +18 -0
  46. package/bootstrap/services/notification/src/commands/handlers/notification.handler.js +157 -0
  47. package/bootstrap/services/notification/src/config.js +15 -0
  48. package/bootstrap/services/notification/src/controllers/message.controller.js +82 -0
  49. package/bootstrap/services/notification/src/services/logger.service.js +16 -0
  50. package/bootstrap/services/notification/src/services/ses.service.js +23 -0
  51. package/bootstrap/services/notification/src/templates/admin-order-recieved.hbs +136 -0
  52. package/bootstrap/services/notification/src/templates/admin-subscription-failed.hbs +87 -0
  53. package/bootstrap/services/notification/src/templates/customer-order-recieved.hbs +132 -0
  54. package/bootstrap/services/notification/src/templates/customer-subscription-failed.hbs +77 -0
  55. package/bootstrap/services/notification/src/tests/notification.test.js +0 -0
  56. package/bootstrap/services/portal/Dockerfile +23 -0
  57. package/bootstrap/services/portal/Dockerfile.remote +40 -0
  58. package/bootstrap/services/portal/README.md +22 -0
  59. package/bootstrap/services/portal/nginx.conf +12 -0
  60. package/bootstrap/services/portal/package.json +59 -0
  61. package/bootstrap/services/portal/public/favicon.ico +0 -0
  62. package/bootstrap/services/portal/public/gnar-white.png +0 -0
  63. package/bootstrap/services/portal/public/gnarengine-logo-black.png +0 -0
  64. package/bootstrap/services/portal/public/index.html +43 -0
  65. package/bootstrap/services/portal/public/logo192.png +0 -0
  66. package/bootstrap/services/portal/public/logo512.png +0 -0
  67. package/bootstrap/services/portal/public/manifest.json +25 -0
  68. package/bootstrap/services/portal/public/robots.txt +3 -0
  69. package/bootstrap/services/portal/src/App.js +56 -0
  70. package/bootstrap/services/portal/src/assets/Logo_Anchord_Black.svg +1 -0
  71. package/bootstrap/services/portal/src/assets/Logo_Anchord_Black_Green.svg +1 -0
  72. package/bootstrap/services/portal/src/assets/Logo_Anchord_White_Green.svg +1 -0
  73. package/bootstrap/services/portal/src/assets/activity.svg +3 -0
  74. package/bootstrap/services/portal/src/assets/arrow.svg +3 -0
  75. package/bootstrap/services/portal/src/assets/bin-white.svg +3 -0
  76. package/bootstrap/services/portal/src/assets/bin.svg +3 -0
  77. package/bootstrap/services/portal/src/assets/check.svg +3 -0
  78. package/bootstrap/services/portal/src/assets/chevron.svg +3 -0
  79. package/bootstrap/services/portal/src/assets/contact.svg +3 -0
  80. package/bootstrap/services/portal/src/assets/dots-vertical.svg +5 -0
  81. package/bootstrap/services/portal/src/assets/eye-off.svg +3 -0
  82. package/bootstrap/services/portal/src/assets/eye.svg +4 -0
  83. package/bootstrap/services/portal/src/assets/gnar-engine-black.svg +47 -0
  84. package/bootstrap/services/portal/src/assets/gnar-engine-white.svg +47 -0
  85. package/bootstrap/services/portal/src/assets/gnar_engine.svg +3 -0
  86. package/bootstrap/services/portal/src/assets/gnarengine-logo-black.png +0 -0
  87. package/bootstrap/services/portal/src/assets/home.svg +3 -0
  88. package/bootstrap/services/portal/src/assets/link.svg +3 -0
  89. package/bootstrap/services/portal/src/assets/lock.svg +3 -0
  90. package/bootstrap/services/portal/src/assets/package.svg +4 -0
  91. package/bootstrap/services/portal/src/assets/raffle.svg +3 -0
  92. package/bootstrap/services/portal/src/assets/settings.svg +4 -0
  93. package/bootstrap/services/portal/src/assets/shopping-bag.svg +3 -0
  94. package/bootstrap/services/portal/src/assets/user-black.svg +3 -0
  95. package/bootstrap/services/portal/src/assets/user.svg +3 -0
  96. package/bootstrap/services/portal/src/assets/users.svg +3 -0
  97. package/bootstrap/services/portal/src/assets/wallet.svg +3 -0
  98. package/bootstrap/services/portal/src/css/style.css +1007 -0
  99. package/bootstrap/services/portal/src/data/data.js +70 -0
  100. package/bootstrap/services/portal/src/features/attributeFormRow/AttributeFormRow.jsx +32 -0
  101. package/bootstrap/services/portal/src/features/billingShipping/BillingShipping.jsx +160 -0
  102. package/bootstrap/services/portal/src/features/crud/crudEdit.less +230 -0
  103. package/bootstrap/services/portal/src/features/crud/crudList.less +134 -0
  104. package/bootstrap/services/portal/src/features/crud/crudPage.less +31 -0
  105. package/bootstrap/services/portal/src/features/crudContact/CrudContactList.jsx +108 -0
  106. package/bootstrap/services/portal/src/features/crudContact/CrudContactSingle.jsx +243 -0
  107. package/bootstrap/services/portal/src/features/crudOrder/CrudOrderList.jsx +109 -0
  108. package/bootstrap/services/portal/src/features/crudOrder/CrudOrderSingle.jsx +315 -0
  109. package/bootstrap/services/portal/src/features/crudProducts/CrudProductList.jsx +104 -0
  110. package/bootstrap/services/portal/src/features/crudProducts/CrudProductSingle.jsx +388 -0
  111. package/bootstrap/services/portal/src/features/crudRaffles/CrudRafflesList.jsx +104 -0
  112. package/bootstrap/services/portal/src/features/crudRaffles/CrudRafflesSingle.jsx +208 -0
  113. package/bootstrap/services/portal/src/features/crudSubscription/CrudSubscriptionList.jsx +110 -0
  114. package/bootstrap/services/portal/src/features/crudSubscription/CrudSubscriptionSingle.jsx +261 -0
  115. package/bootstrap/services/portal/src/features/crudUser/CrudUserList.jsx +107 -0
  116. package/bootstrap/services/portal/src/features/crudUser/CrudUserSingle.jsx +402 -0
  117. package/bootstrap/services/portal/src/features/inventoryFormRow/InventoryFormRow.jsx +30 -0
  118. package/bootstrap/services/portal/src/features/lineItems/LineItems.jsx +113 -0
  119. package/bootstrap/services/portal/src/features/loginForm/LoginForm.jsx +56 -0
  120. package/bootstrap/services/portal/src/features/loginForm/loginForm.less +56 -0
  121. package/bootstrap/services/portal/src/features/notes/Notes.jsx +18 -0
  122. package/bootstrap/services/portal/src/features/passwordReset/PasswordResetForm.jsx +96 -0
  123. package/bootstrap/services/portal/src/features/passwordReset/PasswordResetRequestForm.jsx +74 -0
  124. package/bootstrap/services/portal/src/features/priceFormRow/PriceFormRow.jsx +102 -0
  125. package/bootstrap/services/portal/src/features/priceFormRow/priceFormRow.less +24 -0
  126. package/bootstrap/services/portal/src/features/raffleEntriesList/RaffleEntriesList.jsx +99 -0
  127. package/bootstrap/services/portal/src/features/raffleProductFormRow/RaffleProductFormRow.jsx +46 -0
  128. package/bootstrap/services/portal/src/features/sidebar/Sidebar.jsx +64 -0
  129. package/bootstrap/services/portal/src/features/sidebar/sidebar.less +49 -0
  130. package/bootstrap/services/portal/src/features/skus/Skus.jsx +109 -0
  131. package/bootstrap/services/portal/src/features/subscriptionSchedule/SubscriptionSchedule.jsx +44 -0
  132. package/bootstrap/services/portal/src/features/taxonomyFormRow/TaxonomyFormRow.jsx +32 -0
  133. package/bootstrap/services/portal/src/features/user/User.jsx +54 -0
  134. package/bootstrap/services/portal/src/features/user/user.less +57 -0
  135. package/bootstrap/services/portal/src/includes/utilities.js +259 -0
  136. package/bootstrap/services/portal/src/index.js +14 -0
  137. package/bootstrap/services/portal/src/layouts/CrudLayout.jsx +50 -0
  138. package/bootstrap/services/portal/src/layouts/LoginLayout.jsx +17 -0
  139. package/bootstrap/services/portal/src/layouts/PortalLayout.jsx +48 -0
  140. package/bootstrap/services/portal/src/layouts/loginLayout.less +33 -0
  141. package/bootstrap/services/portal/src/layouts/portalLayout.less +67 -0
  142. package/bootstrap/services/portal/src/pages/contacts/Contacts.jsx +199 -0
  143. package/bootstrap/services/portal/src/pages/dashboard/Dashboard.jsx +17 -0
  144. package/bootstrap/services/portal/src/pages/integrations/Integrations.jsx +10 -0
  145. package/bootstrap/services/portal/src/pages/login/Login.jsx +15 -0
  146. package/bootstrap/services/portal/src/pages/login/login.less +10 -0
  147. package/bootstrap/services/portal/src/pages/orders/Orders.jsx +199 -0
  148. package/bootstrap/services/portal/src/pages/passwordReset/PasswordResetPage.jsx +15 -0
  149. package/bootstrap/services/portal/src/pages/passwordResetRequest/PasswordResetRequestPage.jsx +15 -0
  150. package/bootstrap/services/portal/src/pages/payments/Payments.jsx +10 -0
  151. package/bootstrap/services/portal/src/pages/portal/Portal.jsx +43 -0
  152. package/bootstrap/services/portal/src/pages/products/Products.jsx +212 -0
  153. package/bootstrap/services/portal/src/pages/raffleEntries/RaffleEntries.jsx +124 -0
  154. package/bootstrap/services/portal/src/pages/raffles/Raffles.jsx +186 -0
  155. package/bootstrap/services/portal/src/pages/reports/Reports.jsx +10 -0
  156. package/bootstrap/services/portal/src/pages/settings/Settings.jsx +10 -0
  157. package/bootstrap/services/portal/src/pages/subscriptions/Subscriptions.jsx +199 -0
  158. package/bootstrap/services/portal/src/pages/users/Users.jsx +193 -0
  159. package/bootstrap/services/portal/src/pages/users/users.less +25 -0
  160. package/bootstrap/services/portal/src/slices/authSlice.js +71 -0
  161. package/bootstrap/services/portal/src/store/configureStore.js +12 -0
  162. package/bootstrap/services/portal/src/styles/global.less +159 -0
  163. package/bootstrap/services/portal/src/styles/inputs.less +157 -0
  164. package/bootstrap/services/portal/src/styles/main.less +26 -0
  165. package/bootstrap/services/portal/src/ui/collapsible/Collapsible.jsx +97 -0
  166. package/bootstrap/services/portal/src/ui/collapsible/collapsible.less +23 -0
  167. package/bootstrap/services/portal/src/ui/customCheckbox/CustomCheckbox.jsx +17 -0
  168. package/bootstrap/services/portal/src/ui/customCheckbox/customCheckbox.less +42 -0
  169. package/bootstrap/services/portal/src/ui/customMultiSelect/CustomMultiSelect.jsx +63 -0
  170. package/bootstrap/services/portal/src/ui/customMultiSelect/CustomMultiSelectPeriod.jsx +63 -0
  171. package/bootstrap/services/portal/src/ui/customSelect/CustomSelect.jsx +63 -0
  172. package/bootstrap/services/portal/src/ui/customSelect/customSelect.less +92 -0
  173. package/bootstrap/services/portal/src/ui/goBack/GoBack.jsx +19 -0
  174. package/bootstrap/services/portal/src/ui/loader/Loader.jsx +12 -0
  175. package/bootstrap/services/portal/src/ui/pagination/Pagination.jsx +23 -0
  176. package/bootstrap/services/portal/src/ui/repeater/Repeater.jsx +29 -0
  177. package/bootstrap/services/portal/src/ui/saveButton/SaveButton.jsx +69 -0
  178. package/bootstrap/services/portal/src/ui/saveButton/saveButton.less +0 -0
  179. package/bootstrap/services/rabbit-mq/Dockerfile.prod +9 -0
  180. package/bootstrap/services/user/Dockerfile +23 -0
  181. package/bootstrap/services/user/Dockerfile.prod +37 -0
  182. package/bootstrap/services/user/README.md +8 -0
  183. package/bootstrap/services/user/package.json +16 -0
  184. package/bootstrap/services/user/src/app.js +45 -0
  185. package/bootstrap/services/user/src/commands/session.handler.js +23 -0
  186. package/bootstrap/services/user/src/commands/user.handler.js +286 -0
  187. package/bootstrap/services/user/src/config.js +73 -0
  188. package/bootstrap/services/user/src/controllers/http.controller.js +156 -0
  189. package/bootstrap/services/user/src/controllers/message.controller.js +51 -0
  190. package/bootstrap/services/user/src/db/migrations/01-init.js +50 -0
  191. package/bootstrap/services/user/src/db/migrations/02-user-service-init.js +63 -0
  192. package/bootstrap/services/user/src/db/migrations/03-unauth-sessions.js +43 -0
  193. package/bootstrap/services/user/src/db/seeders/development/01-root-user.js +29 -0
  194. package/bootstrap/services/user/src/db/seeders/development/02-portal-admin-user.js +27 -0
  195. package/bootstrap/services/user/src/db/seeders/production/01-root-user.js +29 -0
  196. package/bootstrap/services/user/src/policies/user.policy.js +81 -0
  197. package/bootstrap/services/user/src/schema/user.schema.js +69 -0
  198. package/bootstrap/services/user/src/services/authentication.service.js +127 -0
  199. package/bootstrap/services/user/src/services/session.service.js +58 -0
  200. package/bootstrap/services/user/src/services/user.service.js +130 -0
  201. package/bootstrap/services/user/src/tests/user.test.js +126 -0
  202. package/package.json +3 -7
  203. package/src/agent/agent.client.js +28 -0
  204. package/src/agent/commands.js +48 -0
  205. package/src/cli.js +30 -0
  206. package/src/config.js +8 -0
  207. package/src/control/commands.js +156 -0
  208. package/src/control/control.client.js +127 -0
  209. package/src/dev/commands.js +71 -0
  210. package/src/dev/dev.service.js +320 -0
  211. package/src/engine/infra.js +142 -0
  212. package/src/helpers/helpers.js +63 -0
  213. package/src/profiles/command.js +170 -0
  214. package/src/profiles/profiles.client.js +101 -0
  215. package/src/scaffolder/commands.js +123 -0
  216. package/src/scaffolder/scaffolder.handler.js +252 -0
  217. package/src/services/client.js +174 -0
  218. package/templates/service/Dockerfile.hbs +20 -0
  219. package/templates/service/app.js.hbs +38 -0
  220. package/templates/service/commands/{{serviceName}}.handler.js.hbs +97 -0
  221. package/templates/service/config.js.hbs +48 -0
  222. package/templates/service/controllers/http.controller.js.hbs +87 -0
  223. package/templates/service/controllers/message.controller.js.hbs +51 -0
  224. package/templates/service/db/migrations/01-init.js.hbs +50 -0
  225. package/templates/service/db/migrations/02-{{lowerCase serviceName}}-service-init.js.hbs +23 -0
  226. package/templates/service/package.json.hbs +18 -0
  227. package/templates/service/policies/{{serviceName}}.policy.js.hbs +49 -0
  228. package/templates/service/schema/{{serviceName}}.schema.js.hbs +14 -0
  229. package/templates/service/services/{{serviceName}}.service.js.hbs +32 -0
  230. package/dist/cli.js +0 -18
@@ -0,0 +1,108 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import gnarEngine from '@gnar-engine/js-client';
3
+ import CustomCheckbox from '../../ui/customCheckbox/CustomCheckbox';
4
+
5
+ const CrudContactList = ({ setSelectedSingleItemId, setView, selectedContactIds, setSelectedContactIds, contacts, message}) => {
6
+
7
+ const allSelected = contacts.length > 0 && selectedContactIds.size === contacts.length;
8
+
9
+ const toggleContactSelection = (contactId) => {
10
+ setSelectedContactIds(prev => {
11
+ const newSet = new Set(prev);
12
+ if (newSet.has(contactId)) {
13
+ newSet.delete(contactId);
14
+ } else {
15
+ newSet.add(contactId);
16
+ }
17
+ return newSet;
18
+ });
19
+ };
20
+
21
+
22
+ const toggleSelectAll = () => {
23
+ if (allSelected) {
24
+ setSelectedContactIds(new Set());
25
+ } else {
26
+ setSelectedContactIds(new Set(contacts.map(contact => contact.id)));
27
+ }
28
+ };
29
+
30
+
31
+ const handleEditClick = (product) => {
32
+ setSelectedSingleItemId(product.id);
33
+ setView('single');
34
+ };
35
+
36
+ const columns = [
37
+ { columnLabel: 'ID', dataKey: 'id' },,
38
+ { columnLabel: 'First Name', dataKey: 'firstName' },
39
+ { columnLabel: 'Last Name', dataKey: 'lastName' },
40
+ { columnLabel: 'Email', dataKey: 'email' },
41
+ { columnLabel: 'Date Added', dataKey: 'createdAt' }
42
+ ];
43
+
44
+
45
+ return (
46
+ <div className="">
47
+ <div className='pagination-labels-cont'>
48
+ <div className='pagination-count'>
49
+ Showing {contacts.length} of {contacts.length} contact{contacts.length !== 1 ? 's' : ''}
50
+ </div>
51
+ <div className="pagination-count">
52
+ {selectedContactIds.size} of {contacts.length} user{contacts.length !== 1 ? 's' : ''} selected
53
+ </div>
54
+ </div>
55
+ <div className='crud-list'>
56
+ <table className='custom-table'>
57
+ <thead>
58
+ <tr>
59
+ <th className="checkbox">
60
+ <CustomCheckbox
61
+ name="selectAll"
62
+ checked={allSelected}
63
+ setChecked={toggleSelectAll}
64
+ />
65
+ </th>
66
+ {columns.map(column => (
67
+ <th key={column.columnLabel}>{column.columnLabel}</th>
68
+ ))}
69
+ </tr>
70
+ </thead>
71
+
72
+ <tbody>
73
+ {message ? (
74
+ <tr>
75
+ <td colSpan={columns.length + 1}>{message}</td>
76
+ </tr>
77
+ ) : (
78
+ contacts.length > 0 ? (
79
+ contacts.map(contact => (
80
+ <tr key={contact.id} onClick={() => handleEditClick(contact)}>
81
+ <td>
82
+ <CustomCheckbox
83
+ name={`checkbox-${contact.id}`}
84
+ checked={selectedContactIds.has(contact.id)}
85
+ setChecked={() => toggleContactSelection(contact.id)}
86
+ />
87
+ </td>
88
+ {columns.map(column => (
89
+ <td key={column.dataKey}>{contact[column.dataKey]}</td>
90
+ ))}
91
+ </tr>
92
+ ))
93
+ ) : (
94
+ <tr>
95
+ <td colSpan={columns.length + 1}>No contacts found</td>
96
+ </tr>
97
+ )
98
+ )}
99
+ </tbody>
100
+ </table>
101
+ </div>
102
+ </div>
103
+
104
+ );
105
+
106
+ };
107
+
108
+ export default CrudContactList;
@@ -0,0 +1,243 @@
1
+ import { useEffect, useState } from "react";
2
+ import gnarEngine from '@gnar-engine/js-client';
3
+ import DatePicker from "react-datepicker";
4
+ import SaveButton from "../../ui/saveButton/SaveButton";
5
+
6
+ const CrudContactSingle = ({ loading, setLoading, contact, setView, refreshSelectedContact, setContact, fetchContacts, formatDate, setSelectedSingleItemId }) => {
7
+
8
+ const [formData, setFormData] = useState({
9
+ firstName: '',
10
+ lastName: '',
11
+ email: '',
12
+ phone: '',
13
+ dateOfBirth: '',
14
+ marketingOptIn: false,
15
+ });
16
+ const [validationErrors, setValidationErrors] = useState([]);
17
+
18
+
19
+ // Load contact details if editing
20
+ useEffect(() => {
21
+ if (contact) {
22
+ setFormData({
23
+ firstName: contact.firstName,
24
+ lastName: contact.lastName,
25
+ email: contact.email,
26
+ phone: contact.phone,
27
+ dateOfBirth: contact.dateOfBirth,
28
+ marketingOptIn: contact.marketingOptIn || false,
29
+ });
30
+ }
31
+ }, [contact]);
32
+
33
+
34
+
35
+ const handleSubmit = async (e) => {
36
+ e.preventDefault();
37
+ setLoading('loading');
38
+ setValidationErrors([]);
39
+
40
+ try {
41
+
42
+ if (contact) {
43
+ const response = await gnarEngine.contacts.update(contact._id, formData);
44
+ console.log('response:', response);
45
+
46
+ setLoading('success');
47
+ setTimeout(() => {
48
+ setLoading(null);
49
+ fetchContacts();
50
+ refreshSelectedContact();
51
+ }, 3000);
52
+
53
+ refreshSelectedContact();
54
+ } else {
55
+
56
+ const response = await gnarEngine.contacts.createContact({
57
+ contacts : [formData]
58
+ });
59
+ console.log('response:', response);
60
+
61
+ if (response.error) {
62
+ setValidationErrors(response.error);
63
+ } else {
64
+
65
+ setLoading('success');
66
+ setTimeout(() => {
67
+ setLoading(null);
68
+ fetchContacts();
69
+ setView('list');
70
+ }, 3000);
71
+
72
+ }
73
+ }
74
+ }
75
+ catch (error) {
76
+ console.error('Error updating contact:', error);
77
+ setValidationErrors(['Error updating contact']);
78
+ setTimeout(() => {
79
+ setLoading(null);
80
+ }, 3000);
81
+ }
82
+
83
+
84
+ }
85
+
86
+ // handle delete user
87
+ const handleDelete = async () => {
88
+ if (window.confirm('Are you sure you want to delete this contact?')) {
89
+ try {
90
+ setLoading('loading');
91
+
92
+ await gnarEngine.contacts.delete(contact._id);
93
+
94
+ setLoading('success');
95
+ setTimeout(() => {
96
+ setLoading(null);
97
+ }, 3000);
98
+
99
+ refreshSelectedContact();
100
+ setView('list');
101
+
102
+ } catch (error) {
103
+
104
+ setLoading('error');
105
+ console.error('Error deleting contact:', error);
106
+ }
107
+ } else {
108
+ console.log('Deletion canceled');
109
+ }
110
+ };
111
+
112
+
113
+
114
+
115
+
116
+ return (
117
+
118
+ <div className="single-edit contact">
119
+ {validationErrors.length > 0 &&
120
+ <div className="error-messages">
121
+ {validationErrors.map((error, index) => {
122
+ return <p key={index}>{error}</p>
123
+ })}
124
+ </div>
125
+ }
126
+
127
+ <div className='single-edit-header'>
128
+ <div className='single-edit-header-left'>
129
+ <h2>{contact ? 'Edit Contact' : 'Add New Contact'}</h2>
130
+ </div>
131
+ <div className='single-edit-header-right'>
132
+ <div className="flex-row-buttons-cont">
133
+ <button onClick={() => {
134
+ setView('list');
135
+ setContact(null);
136
+ setSelectedSingleItemId(null);
137
+ }} className="secondaryButton">
138
+ Back
139
+ </button>
140
+ <button onClick={handleDelete} className="secondaryButton">Delete</button>
141
+ <SaveButton
142
+ save={handleSubmit}
143
+ loading={loading}
144
+ textCreate="Add Contact"
145
+ textCreateLoading="Saving..."
146
+ textCreateSuccess="Saved"
147
+ textCreateError="Error"
148
+ textUpdate="Save"
149
+ textUpdateLoading="Updating..."
150
+ textUpdateSuccess="Updated"
151
+ textUpdateError="Error"
152
+ isUpdating={!!contact}
153
+ />
154
+ </div>
155
+ </div>
156
+ </div>
157
+ <div className="card">
158
+ <div className='card-header'>
159
+ <h2>Contact Details</h2>
160
+ </div>
161
+ <div className='card-content'>
162
+ <form onSubmit={handleSubmit}>
163
+ <div className="form-group">
164
+ <label htmlFor="firstName">First Name</label>
165
+ <input
166
+ type="text"
167
+ id="firstName"
168
+ name="firstName"
169
+ value={formData.firstName}
170
+ onChange={(e) => setFormData({ ...formData, firstName: e.target.value })}
171
+ />
172
+ </div>
173
+ <div className="form-group">
174
+ <label htmlFor="lastName">Last Name</label>
175
+ <input
176
+ type="text"
177
+ id="lastName"
178
+ name="lastName"
179
+ value={formData.lastName}
180
+ onChange={(e) => setFormData({ ...formData, lastName: e.target.value })}
181
+ />
182
+ </div>
183
+ <div className="form-group">
184
+ <label htmlFor="email">Email</label>
185
+ <input
186
+ type="email"
187
+ id="email"
188
+ name="email"
189
+ value={formData.email}
190
+ onChange={(e) => setFormData({ ...formData, email: e.target.value })}
191
+ />
192
+ </div>
193
+ <div className="form-group">
194
+ <label htmlFor="phone">Phone</label>
195
+ <input
196
+ type="text"
197
+ id="phone"
198
+ name="phone"
199
+ value={formData.phone}
200
+ onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
201
+ />
202
+ </div>
203
+ <div className="form-group">
204
+ <label htmlFor="dateOfBirth">Date of Birth (DD/MM/YYYY)</label>
205
+ <DatePicker
206
+ selected={formData.dateOfBirth ? new Date(formData.dateOfBirth) : null}
207
+ onChange={(date) => {
208
+ const formattedDate = date.toISOString().split('T')[0]; // Convert to YYYY-MM-DD format
209
+ setFormData({ ...formData, dateOfBirth: formattedDate });
210
+ }}
211
+ dateFormat="dd/MM/yyyy"
212
+ />
213
+ </div>
214
+ {/* marketingOptIn */}
215
+ <div className="form-group">
216
+ <label htmlFor="marketingOptIn">
217
+ <input
218
+ type="checkbox"
219
+ id="marketingOptIn"
220
+ name="marketingOptIn"
221
+ checked={formData.marketingOptIn}
222
+ onChange={(e) => setFormData({ ...formData, marketingOptIn: e.target.checked })}
223
+ />
224
+ Marketing Opt-In
225
+ </label>
226
+
227
+ </div>
228
+ </form>
229
+ <div>
230
+ <p><strong>Date Added: </strong>{formatDate(contact?.createdAt)}</p>
231
+ </div>
232
+ </div>
233
+
234
+
235
+
236
+ </div>
237
+ </div>
238
+
239
+ );
240
+
241
+ };
242
+
243
+ export default CrudContactSingle;
@@ -0,0 +1,109 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import gnarEngine from '@gnar-engine/js-client';
3
+ import CustomCheckbox from '../../ui/customCheckbox/CustomCheckbox';
4
+
5
+ const CrudOrderList = ({ setSelectedSingleItemId, setView, selectedOrderIds, setSelectedOrderIds, orders, message }) => {
6
+
7
+ const allSelected = orders.length > 0 && selectedOrderIds.size === orders.length;
8
+
9
+ const toggleContactSelection = (orderId) => {
10
+ setSelectedOrderIds(prev => {
11
+ const newSet = new Set(prev);
12
+ if (newSet.has(orderId)) {
13
+ newSet.delete(orderId);
14
+ } else {
15
+ newSet.add(orderId);
16
+ }
17
+ return newSet;
18
+ });
19
+ };
20
+
21
+
22
+ const toggleSelectAll = () => {
23
+ if (allSelected) {
24
+ setSelectedOrderIds(new Set());
25
+ } else {
26
+ setSelectedOrderIds(new Set(orders.map(order => order.id)));
27
+ }
28
+ };
29
+
30
+ const handleEditClick = (product) => {
31
+ setSelectedSingleItemId(product.id);
32
+ setView('single');
33
+ };
34
+
35
+ const columns = [
36
+ { columnLabel: 'Order', dataKey: 'id' },
37
+ { columnLabel: 'Type', dataKey: 'type' },
38
+ { columnLabel: 'First Name', dataKey: 'firstName' },
39
+ { columnLabel: 'Last Name', dataKey: 'lastName' },
40
+ { columnLabel: 'Status', dataKey: 'status' },
41
+ { columnLabel: 'Total', dataKey: 'total' },
42
+ { columnLabel: 'Date added', dataKey: 'createdAt' },
43
+ ];
44
+
45
+
46
+ return (
47
+ <div className="">
48
+ <div className='pagination-labels-cont'>
49
+ <div className='pagination-count'>
50
+ Showing {orders.length} of {orders.length} order{orders.length !== 1 ? 's' : ''}
51
+ </div>
52
+ <div className="pagination-count">
53
+ {selectedOrderIds.size} of {orders.length} order{orders.length !== 1 ? 's' : ''} selected
54
+ </div>
55
+ </div>
56
+ <div className='crud-list'>
57
+ <table className='custom-table'>
58
+ <thead>
59
+ <tr>
60
+ <th className="checkbox">
61
+ <CustomCheckbox
62
+ name="selectAll"
63
+ checked={allSelected}
64
+ setChecked={toggleSelectAll}
65
+ />
66
+ </th>
67
+ {columns.map(column => (
68
+ <th key={column.columnLabel}>{column.columnLabel}</th>
69
+ ))}
70
+ </tr>
71
+ </thead>
72
+
73
+ <tbody>
74
+ {message ? (
75
+ <tr>
76
+ <td colSpan={columns.length + 1}>{message}</td>
77
+ </tr>
78
+ ) : (
79
+ orders.length > 0 ? (
80
+ orders.map(order => (
81
+ <tr key={order.id} onClick={() => handleEditClick(order)}>
82
+ <td>
83
+ <CustomCheckbox
84
+ name={`checkbox-${order.id}`}
85
+ checked={selectedOrderIds.has(order.id)}
86
+ setChecked={() => toggleContactSelection(order.id)}
87
+ />
88
+ </td>
89
+ {columns.map(column => (
90
+ <td key={column.dataKey}>{order[column.dataKey]}</td>
91
+ ))}
92
+ </tr>
93
+ ))
94
+ ) : (
95
+ <tr>
96
+ <td colSpan={columns.length + 1}>No orders found</td>
97
+ </tr>
98
+ )
99
+ )}
100
+ </tbody>
101
+ </table>
102
+ </div>
103
+ </div>
104
+
105
+ );
106
+
107
+ };
108
+
109
+ export default CrudOrderList;