@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.
- package/assets/gnar-engine-logo-white.svg +9 -0
- package/bootstrap/deploy.localdev.yml +51 -0
- package/bootstrap/secrets.localdev.yml +27 -0
- package/bootstrap/services/agent/Dockerfile +23 -0
- package/bootstrap/services/agent/notes.md +28 -0
- package/bootstrap/services/agent/package.json +16 -0
- package/bootstrap/services/agent/src/app.js +52 -0
- package/bootstrap/services/agent/src/commands/agent.handler.js +104 -0
- package/bootstrap/services/agent/src/config.js +52 -0
- package/bootstrap/services/agent/src/controllers/http.controller.js +44 -0
- package/bootstrap/services/agent/src/controllers/message.controller.js +51 -0
- package/bootstrap/services/agent/src/db/migrations/01-init.js +50 -0
- package/bootstrap/services/agent/src/db/migrations/02-agent-service-init.js +36 -0
- package/bootstrap/services/agent/src/policies/agent.policy.js +13 -0
- package/bootstrap/services/agent/src/schema/Agent.schema.js +17 -0
- package/bootstrap/services/agent/src/services/agent.service.js +259 -0
- package/bootstrap/services/agent/src/services/chatgpt.service.js +46 -0
- package/bootstrap/services/agent/src/services/manifest.service.js +21 -0
- package/bootstrap/services/control/Dockerfile +23 -0
- package/bootstrap/services/control/Dockerfile.prod +37 -0
- package/bootstrap/services/control/README.md +25 -0
- package/bootstrap/services/control/package.json +16 -0
- package/bootstrap/services/control/src/app.js +45 -0
- package/bootstrap/services/control/src/commands/control.handler.js +231 -0
- package/bootstrap/services/control/src/commands/service.handler.js +81 -0
- package/bootstrap/services/control/src/commands/task.handler.js +247 -0
- package/bootstrap/services/control/src/config.js +55 -0
- package/bootstrap/services/control/src/controllers/http.controller.js +228 -0
- package/bootstrap/services/control/src/controllers/message.controller.js +40 -0
- package/bootstrap/services/control/src/db/migrations/01-init.js +50 -0
- package/bootstrap/services/control/src/db/migrations/02-control-service-init.js +60 -0
- package/bootstrap/services/control/src/db/migrations/03-alter-tasks.js +29 -0
- package/bootstrap/services/control/src/policies/task.policy.js +53 -0
- package/bootstrap/services/control/src/schema/control.schema.js +42 -0
- package/bootstrap/services/control/src/services/registry.service.js +83 -0
- package/bootstrap/services/control/src/services/reset.service.js +28 -0
- package/bootstrap/services/control/src/services/task.service.js +153 -0
- package/bootstrap/services/control/src/tests/control.test.js +50 -0
- package/bootstrap/services/notification/Dockerfile +23 -0
- package/bootstrap/services/notification/Dockerfile.prod +37 -0
- package/bootstrap/services/notification/README.md +3 -0
- package/bootstrap/services/notification/package.json +34 -0
- package/bootstrap/services/notification/src/app.js +51 -0
- package/bootstrap/services/notification/src/commands/command-bus.js +20 -0
- package/bootstrap/services/notification/src/commands/handlers/control.handler.js +18 -0
- package/bootstrap/services/notification/src/commands/handlers/notification.handler.js +157 -0
- package/bootstrap/services/notification/src/config.js +15 -0
- package/bootstrap/services/notification/src/controllers/message.controller.js +82 -0
- package/bootstrap/services/notification/src/services/logger.service.js +16 -0
- package/bootstrap/services/notification/src/services/ses.service.js +23 -0
- package/bootstrap/services/notification/src/templates/admin-order-recieved.hbs +136 -0
- package/bootstrap/services/notification/src/templates/admin-subscription-failed.hbs +87 -0
- package/bootstrap/services/notification/src/templates/customer-order-recieved.hbs +132 -0
- package/bootstrap/services/notification/src/templates/customer-subscription-failed.hbs +77 -0
- package/bootstrap/services/notification/src/tests/notification.test.js +0 -0
- package/bootstrap/services/portal/Dockerfile +23 -0
- package/bootstrap/services/portal/Dockerfile.remote +40 -0
- package/bootstrap/services/portal/README.md +22 -0
- package/bootstrap/services/portal/nginx.conf +12 -0
- package/bootstrap/services/portal/package.json +59 -0
- package/bootstrap/services/portal/public/favicon.ico +0 -0
- package/bootstrap/services/portal/public/gnar-white.png +0 -0
- package/bootstrap/services/portal/public/gnarengine-logo-black.png +0 -0
- package/bootstrap/services/portal/public/index.html +43 -0
- package/bootstrap/services/portal/public/logo192.png +0 -0
- package/bootstrap/services/portal/public/logo512.png +0 -0
- package/bootstrap/services/portal/public/manifest.json +25 -0
- package/bootstrap/services/portal/public/robots.txt +3 -0
- package/bootstrap/services/portal/src/App.js +56 -0
- package/bootstrap/services/portal/src/assets/Logo_Anchord_Black.svg +1 -0
- package/bootstrap/services/portal/src/assets/Logo_Anchord_Black_Green.svg +1 -0
- package/bootstrap/services/portal/src/assets/Logo_Anchord_White_Green.svg +1 -0
- package/bootstrap/services/portal/src/assets/activity.svg +3 -0
- package/bootstrap/services/portal/src/assets/arrow.svg +3 -0
- package/bootstrap/services/portal/src/assets/bin-white.svg +3 -0
- package/bootstrap/services/portal/src/assets/bin.svg +3 -0
- package/bootstrap/services/portal/src/assets/check.svg +3 -0
- package/bootstrap/services/portal/src/assets/chevron.svg +3 -0
- package/bootstrap/services/portal/src/assets/contact.svg +3 -0
- package/bootstrap/services/portal/src/assets/dots-vertical.svg +5 -0
- package/bootstrap/services/portal/src/assets/eye-off.svg +3 -0
- package/bootstrap/services/portal/src/assets/eye.svg +4 -0
- package/bootstrap/services/portal/src/assets/gnar-engine-black.svg +47 -0
- package/bootstrap/services/portal/src/assets/gnar-engine-white.svg +47 -0
- package/bootstrap/services/portal/src/assets/gnar_engine.svg +3 -0
- package/bootstrap/services/portal/src/assets/gnarengine-logo-black.png +0 -0
- package/bootstrap/services/portal/src/assets/home.svg +3 -0
- package/bootstrap/services/portal/src/assets/link.svg +3 -0
- package/bootstrap/services/portal/src/assets/lock.svg +3 -0
- package/bootstrap/services/portal/src/assets/package.svg +4 -0
- package/bootstrap/services/portal/src/assets/raffle.svg +3 -0
- package/bootstrap/services/portal/src/assets/settings.svg +4 -0
- package/bootstrap/services/portal/src/assets/shopping-bag.svg +3 -0
- package/bootstrap/services/portal/src/assets/user-black.svg +3 -0
- package/bootstrap/services/portal/src/assets/user.svg +3 -0
- package/bootstrap/services/portal/src/assets/users.svg +3 -0
- package/bootstrap/services/portal/src/assets/wallet.svg +3 -0
- package/bootstrap/services/portal/src/css/style.css +1007 -0
- package/bootstrap/services/portal/src/data/data.js +70 -0
- package/bootstrap/services/portal/src/features/attributeFormRow/AttributeFormRow.jsx +32 -0
- package/bootstrap/services/portal/src/features/billingShipping/BillingShipping.jsx +160 -0
- package/bootstrap/services/portal/src/features/crud/crudEdit.less +230 -0
- package/bootstrap/services/portal/src/features/crud/crudList.less +134 -0
- package/bootstrap/services/portal/src/features/crud/crudPage.less +31 -0
- package/bootstrap/services/portal/src/features/crudContact/CrudContactList.jsx +108 -0
- package/bootstrap/services/portal/src/features/crudContact/CrudContactSingle.jsx +243 -0
- package/bootstrap/services/portal/src/features/crudOrder/CrudOrderList.jsx +109 -0
- package/bootstrap/services/portal/src/features/crudOrder/CrudOrderSingle.jsx +315 -0
- package/bootstrap/services/portal/src/features/crudProducts/CrudProductList.jsx +104 -0
- package/bootstrap/services/portal/src/features/crudProducts/CrudProductSingle.jsx +388 -0
- package/bootstrap/services/portal/src/features/crudRaffles/CrudRafflesList.jsx +104 -0
- package/bootstrap/services/portal/src/features/crudRaffles/CrudRafflesSingle.jsx +208 -0
- package/bootstrap/services/portal/src/features/crudSubscription/CrudSubscriptionList.jsx +110 -0
- package/bootstrap/services/portal/src/features/crudSubscription/CrudSubscriptionSingle.jsx +261 -0
- package/bootstrap/services/portal/src/features/crudUser/CrudUserList.jsx +107 -0
- package/bootstrap/services/portal/src/features/crudUser/CrudUserSingle.jsx +402 -0
- package/bootstrap/services/portal/src/features/inventoryFormRow/InventoryFormRow.jsx +30 -0
- package/bootstrap/services/portal/src/features/lineItems/LineItems.jsx +113 -0
- package/bootstrap/services/portal/src/features/loginForm/LoginForm.jsx +56 -0
- package/bootstrap/services/portal/src/features/loginForm/loginForm.less +56 -0
- package/bootstrap/services/portal/src/features/notes/Notes.jsx +18 -0
- package/bootstrap/services/portal/src/features/passwordReset/PasswordResetForm.jsx +96 -0
- package/bootstrap/services/portal/src/features/passwordReset/PasswordResetRequestForm.jsx +74 -0
- package/bootstrap/services/portal/src/features/priceFormRow/PriceFormRow.jsx +102 -0
- package/bootstrap/services/portal/src/features/priceFormRow/priceFormRow.less +24 -0
- package/bootstrap/services/portal/src/features/raffleEntriesList/RaffleEntriesList.jsx +99 -0
- package/bootstrap/services/portal/src/features/raffleProductFormRow/RaffleProductFormRow.jsx +46 -0
- package/bootstrap/services/portal/src/features/sidebar/Sidebar.jsx +64 -0
- package/bootstrap/services/portal/src/features/sidebar/sidebar.less +49 -0
- package/bootstrap/services/portal/src/features/skus/Skus.jsx +109 -0
- package/bootstrap/services/portal/src/features/subscriptionSchedule/SubscriptionSchedule.jsx +44 -0
- package/bootstrap/services/portal/src/features/taxonomyFormRow/TaxonomyFormRow.jsx +32 -0
- package/bootstrap/services/portal/src/features/user/User.jsx +54 -0
- package/bootstrap/services/portal/src/features/user/user.less +57 -0
- package/bootstrap/services/portal/src/includes/utilities.js +259 -0
- package/bootstrap/services/portal/src/index.js +14 -0
- package/bootstrap/services/portal/src/layouts/CrudLayout.jsx +50 -0
- package/bootstrap/services/portal/src/layouts/LoginLayout.jsx +17 -0
- package/bootstrap/services/portal/src/layouts/PortalLayout.jsx +48 -0
- package/bootstrap/services/portal/src/layouts/loginLayout.less +33 -0
- package/bootstrap/services/portal/src/layouts/portalLayout.less +67 -0
- package/bootstrap/services/portal/src/pages/contacts/Contacts.jsx +199 -0
- package/bootstrap/services/portal/src/pages/dashboard/Dashboard.jsx +17 -0
- package/bootstrap/services/portal/src/pages/integrations/Integrations.jsx +10 -0
- package/bootstrap/services/portal/src/pages/login/Login.jsx +15 -0
- package/bootstrap/services/portal/src/pages/login/login.less +10 -0
- package/bootstrap/services/portal/src/pages/orders/Orders.jsx +199 -0
- package/bootstrap/services/portal/src/pages/passwordReset/PasswordResetPage.jsx +15 -0
- package/bootstrap/services/portal/src/pages/passwordResetRequest/PasswordResetRequestPage.jsx +15 -0
- package/bootstrap/services/portal/src/pages/payments/Payments.jsx +10 -0
- package/bootstrap/services/portal/src/pages/portal/Portal.jsx +43 -0
- package/bootstrap/services/portal/src/pages/products/Products.jsx +212 -0
- package/bootstrap/services/portal/src/pages/raffleEntries/RaffleEntries.jsx +124 -0
- package/bootstrap/services/portal/src/pages/raffles/Raffles.jsx +186 -0
- package/bootstrap/services/portal/src/pages/reports/Reports.jsx +10 -0
- package/bootstrap/services/portal/src/pages/settings/Settings.jsx +10 -0
- package/bootstrap/services/portal/src/pages/subscriptions/Subscriptions.jsx +199 -0
- package/bootstrap/services/portal/src/pages/users/Users.jsx +193 -0
- package/bootstrap/services/portal/src/pages/users/users.less +25 -0
- package/bootstrap/services/portal/src/slices/authSlice.js +71 -0
- package/bootstrap/services/portal/src/store/configureStore.js +12 -0
- package/bootstrap/services/portal/src/styles/global.less +159 -0
- package/bootstrap/services/portal/src/styles/inputs.less +157 -0
- package/bootstrap/services/portal/src/styles/main.less +26 -0
- package/bootstrap/services/portal/src/ui/collapsible/Collapsible.jsx +97 -0
- package/bootstrap/services/portal/src/ui/collapsible/collapsible.less +23 -0
- package/bootstrap/services/portal/src/ui/customCheckbox/CustomCheckbox.jsx +17 -0
- package/bootstrap/services/portal/src/ui/customCheckbox/customCheckbox.less +42 -0
- package/bootstrap/services/portal/src/ui/customMultiSelect/CustomMultiSelect.jsx +63 -0
- package/bootstrap/services/portal/src/ui/customMultiSelect/CustomMultiSelectPeriod.jsx +63 -0
- package/bootstrap/services/portal/src/ui/customSelect/CustomSelect.jsx +63 -0
- package/bootstrap/services/portal/src/ui/customSelect/customSelect.less +92 -0
- package/bootstrap/services/portal/src/ui/goBack/GoBack.jsx +19 -0
- package/bootstrap/services/portal/src/ui/loader/Loader.jsx +12 -0
- package/bootstrap/services/portal/src/ui/pagination/Pagination.jsx +23 -0
- package/bootstrap/services/portal/src/ui/repeater/Repeater.jsx +29 -0
- package/bootstrap/services/portal/src/ui/saveButton/SaveButton.jsx +69 -0
- package/bootstrap/services/portal/src/ui/saveButton/saveButton.less +0 -0
- package/bootstrap/services/rabbit-mq/Dockerfile.prod +9 -0
- package/bootstrap/services/user/Dockerfile +23 -0
- package/bootstrap/services/user/Dockerfile.prod +37 -0
- package/bootstrap/services/user/README.md +8 -0
- package/bootstrap/services/user/package.json +16 -0
- package/bootstrap/services/user/src/app.js +45 -0
- package/bootstrap/services/user/src/commands/session.handler.js +23 -0
- package/bootstrap/services/user/src/commands/user.handler.js +286 -0
- package/bootstrap/services/user/src/config.js +73 -0
- package/bootstrap/services/user/src/controllers/http.controller.js +156 -0
- package/bootstrap/services/user/src/controllers/message.controller.js +51 -0
- package/bootstrap/services/user/src/db/migrations/01-init.js +50 -0
- package/bootstrap/services/user/src/db/migrations/02-user-service-init.js +63 -0
- package/bootstrap/services/user/src/db/migrations/03-unauth-sessions.js +43 -0
- package/bootstrap/services/user/src/db/seeders/development/01-root-user.js +29 -0
- package/bootstrap/services/user/src/db/seeders/development/02-portal-admin-user.js +27 -0
- package/bootstrap/services/user/src/db/seeders/production/01-root-user.js +29 -0
- package/bootstrap/services/user/src/policies/user.policy.js +81 -0
- package/bootstrap/services/user/src/schema/user.schema.js +69 -0
- package/bootstrap/services/user/src/services/authentication.service.js +127 -0
- package/bootstrap/services/user/src/services/session.service.js +58 -0
- package/bootstrap/services/user/src/services/user.service.js +130 -0
- package/bootstrap/services/user/src/tests/user.test.js +126 -0
- package/package.json +3 -7
- package/src/agent/agent.client.js +28 -0
- package/src/agent/commands.js +48 -0
- package/src/cli.js +30 -0
- package/src/config.js +8 -0
- package/src/control/commands.js +156 -0
- package/src/control/control.client.js +127 -0
- package/src/dev/commands.js +71 -0
- package/src/dev/dev.service.js +320 -0
- package/src/engine/infra.js +142 -0
- package/src/helpers/helpers.js +63 -0
- package/src/profiles/command.js +170 -0
- package/src/profiles/profiles.client.js +101 -0
- package/src/scaffolder/commands.js +123 -0
- package/src/scaffolder/scaffolder.handler.js +252 -0
- package/src/services/client.js +174 -0
- package/templates/service/Dockerfile.hbs +20 -0
- package/templates/service/app.js.hbs +38 -0
- package/templates/service/commands/{{serviceName}}.handler.js.hbs +97 -0
- package/templates/service/config.js.hbs +48 -0
- package/templates/service/controllers/http.controller.js.hbs +87 -0
- package/templates/service/controllers/message.controller.js.hbs +51 -0
- package/templates/service/db/migrations/01-init.js.hbs +50 -0
- package/templates/service/db/migrations/02-{{lowerCase serviceName}}-service-init.js.hbs +23 -0
- package/templates/service/package.json.hbs +18 -0
- package/templates/service/policies/{{serviceName}}.policy.js.hbs +49 -0
- package/templates/service/schema/{{serviceName}}.schema.js.hbs +14 -0
- package/templates/service/services/{{serviceName}}.service.js.hbs +32 -0
- package/dist/cli.js +0 -18
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import CrudLayout from "../../layouts/CrudLayout";
|
|
3
|
+
import gnarEngine from "@gnar-engine/js-client";
|
|
4
|
+
import CustomSelect from "../../ui/customSelect/CustomSelect";
|
|
5
|
+
import arrow from '../../assets/arrow.svg';
|
|
6
|
+
import CrudSubscriptionList from "../../features/crudSubscription/CrudSubscriptionList";
|
|
7
|
+
import CrudSubscriptionSingle from "../../features/crudSubscription/CrudSubscriptionSingle";
|
|
8
|
+
|
|
9
|
+
const Subscriptions = () => {
|
|
10
|
+
|
|
11
|
+
const [view, setView] = useState("list");
|
|
12
|
+
const [selectedSingleItemId, setSelectedSingleItemId] = useState(null);
|
|
13
|
+
const [selectedSubscription, setSubscription] = useState(null);
|
|
14
|
+
const [loading, setLoading] = useState(false);
|
|
15
|
+
const [selectedAction, setSelectedAction] = useState(null);
|
|
16
|
+
const [selectedSubscriptionIds, setSelectedSubscriptionIds] = useState(new Set());
|
|
17
|
+
const [subscriptions, setSubscriptions] = useState([]);
|
|
18
|
+
const [message, setMessage] = useState('');
|
|
19
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const fetchSubscriptions = async () => {
|
|
23
|
+
try {
|
|
24
|
+
const data = await gnarEngine.subscription.getSubscriptions();
|
|
25
|
+
console.log('data:', data);
|
|
26
|
+
|
|
27
|
+
const subscriptionsList = data.subscriptions.map(order => ({
|
|
28
|
+
id: order._id,
|
|
29
|
+
firstName: order.billingAddress.firstName,
|
|
30
|
+
lastName: order.billingAddress.lastName,
|
|
31
|
+
date: new Date(order.createdAt).toLocaleDateString(),
|
|
32
|
+
status: order.status,
|
|
33
|
+
total: '£' + order.total?.toFixed(2),
|
|
34
|
+
createdAt: formatDate(order.createdAt),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
setSubscriptions(subscriptionsList);
|
|
38
|
+
setMessage(subscriptionsList.length > 0 ? '' : 'No subscriptions found');
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Error fetching subscriptions:', error);
|
|
41
|
+
setSubscriptions([]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
fetchSubscriptions();
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
const formatDate = (isoString) => {
|
|
50
|
+
if (!isoString) return "N/A";
|
|
51
|
+
|
|
52
|
+
const date = new Date(isoString);
|
|
53
|
+
if (isNaN(date.getTime())) return "N/A"; // Checks if the date is invalid
|
|
54
|
+
|
|
55
|
+
return `${date.getFullYear()}/${String(date.getMonth() + 1).padStart(2, '0')}/${String(date.getDate()).padStart(2, '0')} at ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const handleAddNew = () => {
|
|
60
|
+
setView("single");
|
|
61
|
+
setSelectedSingleItemId(null);
|
|
62
|
+
setSubscription(null);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const refreshSelectedSubscription = () => {
|
|
66
|
+
if (!selectedSingleItemId) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
(async () => {
|
|
70
|
+
try {
|
|
71
|
+
const data = await gnarEngine.subscription.getSubscriptions(selectedSingleItemId);
|
|
72
|
+
setSubscription(data.subscription);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('Error fetching subscription:', error);
|
|
75
|
+
}
|
|
76
|
+
})();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
(async () => {
|
|
81
|
+
if (!selectedSingleItemId) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
// fetch contact data
|
|
86
|
+
const data = await gnarEngine.subscription.getSubscription(selectedSingleItemId);
|
|
87
|
+
setSubscription(data.subscription);
|
|
88
|
+
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error('Error fetching subscription:', error);
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
93
|
+
}, [selectedSingleItemId]);
|
|
94
|
+
|
|
95
|
+
const handleAction = () => {
|
|
96
|
+
if (!selectedAction) {
|
|
97
|
+
alert("Please select an action first!");
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (selectedAction.id === "delete") {
|
|
102
|
+
handleDelete();
|
|
103
|
+
} else if (selectedAction.id === "export") {
|
|
104
|
+
console.log("Export action triggered");
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handleDelete = () => {
|
|
109
|
+
if (selectedSubscriptionIds.size === 0) {
|
|
110
|
+
alert("Please select a subscription to delete first!");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!window.confirm(`Are you sure you want to delete ${selectedSubscriptionIds.size} subscription(s)?`)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
(async () => {
|
|
117
|
+
try {
|
|
118
|
+
for (const subscriptionId of selectedSubscriptionIds) {
|
|
119
|
+
await gnarEngine.subscription.deleteSubscription(subscriptionId);
|
|
120
|
+
}
|
|
121
|
+
setSelectedSubscriptionIds(new Set());
|
|
122
|
+
setSelectedAction(null);
|
|
123
|
+
await fetchSubscriptions();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('Error deleting subscription:', error);
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<CrudLayout
|
|
132
|
+
view={view}
|
|
133
|
+
setView={setView}
|
|
134
|
+
selectedSingleItemId={selectedSingleItemId}
|
|
135
|
+
setSelectedSingleItemId={setSelectedSingleItemId}
|
|
136
|
+
>
|
|
137
|
+
<div className="crud-page">
|
|
138
|
+
|
|
139
|
+
{view === "list" ? (
|
|
140
|
+
<div className="crud-list-cont">
|
|
141
|
+
<div className="crud-list-controls">
|
|
142
|
+
<div className="controls-left-col">
|
|
143
|
+
<button onClick={handleAddNew} className="add-new">Add new</button>
|
|
144
|
+
</div>
|
|
145
|
+
<div className="controls-right-col">
|
|
146
|
+
<CustomSelect
|
|
147
|
+
name="filter-contacts"
|
|
148
|
+
placeholder="filter by"
|
|
149
|
+
options={[
|
|
150
|
+
{ id: "all", name: "All" },
|
|
151
|
+
{ id: "admin", name: "Admin" },
|
|
152
|
+
{ id: "contact", name: "User" }
|
|
153
|
+
]}
|
|
154
|
+
labelKey="name"
|
|
155
|
+
setSelectedOption={() => {}}
|
|
156
|
+
selectedOption={null}
|
|
157
|
+
/>
|
|
158
|
+
<CustomSelect
|
|
159
|
+
name="action"
|
|
160
|
+
placeholder="action"
|
|
161
|
+
options={[
|
|
162
|
+
{ id: "delete", name: "Delete" },
|
|
163
|
+
// { id: "export", name: "Export" }
|
|
164
|
+
]}
|
|
165
|
+
labelKey="name"
|
|
166
|
+
setSelectedOption={setSelectedAction}
|
|
167
|
+
selectedOption={selectedAction}
|
|
168
|
+
/>
|
|
169
|
+
<button className="arrowButton" onClick={handleAction}><img src={arrow} alt="right arrow icon" /></button>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
<CrudSubscriptionList
|
|
173
|
+
setSelectedSingleItemId={setSelectedSingleItemId}
|
|
174
|
+
setView={() => setView('single')}
|
|
175
|
+
selectedSubscriptionIds={selectedSubscriptionIds}
|
|
176
|
+
setSelectedSubscriptionIds={setSelectedSubscriptionIds}
|
|
177
|
+
subscriptions={subscriptions}
|
|
178
|
+
message={message}
|
|
179
|
+
/>
|
|
180
|
+
</div>
|
|
181
|
+
) : (
|
|
182
|
+
<CrudSubscriptionSingle
|
|
183
|
+
loading={loading}
|
|
184
|
+
setLoading={setLoading}
|
|
185
|
+
subscription={selectedSubscription}
|
|
186
|
+
setView={() => setView('list')}
|
|
187
|
+
refreshSelectedSubscription={refreshSelectedSubscription}
|
|
188
|
+
setSubscription={setSubscription}
|
|
189
|
+
fetchSubscriptions={fetchSubscriptions}
|
|
190
|
+
setSelectedSingleItemId={setSelectedSingleItemId}
|
|
191
|
+
formatDate={formatDate}
|
|
192
|
+
/>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
</CrudLayout>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export default Subscriptions;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import CrudLayout from "../../layouts/CrudLayout";
|
|
3
|
+
import CrudUserList from '../../features/crudUser/CrudUserList';
|
|
4
|
+
import CrudUserSingle from '../../features/crudUser/CrudUserSingle';
|
|
5
|
+
import gnarEngine from "@gnar-engine/js-client";
|
|
6
|
+
import CustomSelect from "../../ui/customSelect/CustomSelect";
|
|
7
|
+
import arrow from '../../assets/arrow.svg';
|
|
8
|
+
|
|
9
|
+
const ManageUsers = () => {
|
|
10
|
+
|
|
11
|
+
const [view, setView] = useState("list");
|
|
12
|
+
const [selectedSingleItemId, setSelectedSingleItemId] = useState(null);
|
|
13
|
+
const [selectedUser, setUser] = useState(null);
|
|
14
|
+
const [loading, setLoading] = useState(false);
|
|
15
|
+
const [selectedAction, setSelectedAction] = useState(null);
|
|
16
|
+
const [selectedUserIds, setSelectedUserIds] = useState(new Set());
|
|
17
|
+
const [users, setUsers] = useState([]);
|
|
18
|
+
const [message, setMessage] = useState('');
|
|
19
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
20
|
+
|
|
21
|
+
const fetchUsers = async () => {
|
|
22
|
+
try {
|
|
23
|
+
const data = await gnarEngine.user.getMany();
|
|
24
|
+
const usersList = data.users.map(user => ({
|
|
25
|
+
id: user.id,
|
|
26
|
+
email: user.email,
|
|
27
|
+
username: user.username,
|
|
28
|
+
userRole: user.role,
|
|
29
|
+
createdAt: formatDate(user.createdAt),
|
|
30
|
+
}));
|
|
31
|
+
setUsers(usersList);
|
|
32
|
+
setMessage(usersList.length > 0 ? '' : 'No users found');
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error('Error fetching users:', error);
|
|
35
|
+
setMessage('Error fetching users');
|
|
36
|
+
setUsers([]);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
fetchUsers();
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const formatDate = (isoString) => {
|
|
47
|
+
if (!isoString) return "N/A";
|
|
48
|
+
|
|
49
|
+
const date = new Date(isoString);
|
|
50
|
+
if (isNaN(date.getTime())) return "N/A"; // Checks if the date is invalid
|
|
51
|
+
|
|
52
|
+
return `${date.getFullYear()}/${String(date.getMonth() + 1).padStart(2, '0')}/${String(date.getDate()).padStart(2, '0')} at ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const handleAddNew = () => {
|
|
57
|
+
setView("single");
|
|
58
|
+
setSelectedSingleItemId(null);
|
|
59
|
+
setUser(null);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const refreshSelectedUser = (user) => {
|
|
63
|
+
setUser(user);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
(async () => {
|
|
68
|
+
if (!selectedSingleItemId) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
// fetch user data
|
|
73
|
+
const data = await gnarEngine.user.getUser(selectedSingleItemId);
|
|
74
|
+
setUser(data.user);
|
|
75
|
+
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error('Error fetching user:', error);
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
80
|
+
}, [selectedSingleItemId]);
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const handleAction = () => {
|
|
84
|
+
if (!selectedAction) {
|
|
85
|
+
alert("Please select an action first!");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (selectedAction.id === "delete") {
|
|
90
|
+
handleDelete();
|
|
91
|
+
} else if (selectedAction.id === "export") {
|
|
92
|
+
console.log("Export action triggered");
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
const handleDelete = () => {
|
|
98
|
+
if (selectedUserIds.size === 0) {
|
|
99
|
+
alert("Please select at least one user to delete.");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!window.confirm(`Are you sure you want to delete ${selectedUserIds.size} user(s)?`)) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
(async () => {
|
|
108
|
+
try {
|
|
109
|
+
setLoading(true);
|
|
110
|
+
for (let userId of selectedUserIds) {
|
|
111
|
+
await gnarEngine.user.delete(userId);
|
|
112
|
+
}
|
|
113
|
+
setSelectedUserIds(new Set());
|
|
114
|
+
setLoading(false);
|
|
115
|
+
await fetchUsers();
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error('Error deleting users:', error);
|
|
118
|
+
setLoading(false);
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<CrudLayout
|
|
126
|
+
view={view}
|
|
127
|
+
setView={setView}
|
|
128
|
+
selectedSingleItemId={selectedSingleItemId}
|
|
129
|
+
setSelectedSingleItemId={setSelectedSingleItemId}
|
|
130
|
+
>
|
|
131
|
+
<div className="crud-page">
|
|
132
|
+
|
|
133
|
+
{view === "list" ? (
|
|
134
|
+
<div className="crud-list-cont">
|
|
135
|
+
<div className="crud-list-controls">
|
|
136
|
+
<div className="controls-left-col">
|
|
137
|
+
<button onClick={handleAddNew} className="add-new">Add new</button>
|
|
138
|
+
</div>
|
|
139
|
+
<div className="controls-right-col">
|
|
140
|
+
<CustomSelect
|
|
141
|
+
name="filter-users"
|
|
142
|
+
placeholder="filter by"
|
|
143
|
+
options={[
|
|
144
|
+
{ id: "all", name: "All" },
|
|
145
|
+
{ id: "admin", name: "Admin" },
|
|
146
|
+
{ id: "user", name: "User" }
|
|
147
|
+
]}
|
|
148
|
+
labelKey="name"
|
|
149
|
+
setSelectedOption={() => {}}
|
|
150
|
+
selectedOption={null}
|
|
151
|
+
/>
|
|
152
|
+
<CustomSelect
|
|
153
|
+
name="action"
|
|
154
|
+
placeholder="action"
|
|
155
|
+
options={[
|
|
156
|
+
{ id: "delete", name: "Delete" },
|
|
157
|
+
// { id: "export", name: "Export" }
|
|
158
|
+
]}
|
|
159
|
+
labelKey="name"
|
|
160
|
+
setSelectedOption={setSelectedAction}
|
|
161
|
+
selectedOption={selectedAction}
|
|
162
|
+
/>
|
|
163
|
+
<button className="arrowButton" onClick={handleAction}><img src={arrow} alt="right arrow icon" /></button>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
<CrudUserList
|
|
167
|
+
setSelectedSingleItemId={setSelectedSingleItemId}
|
|
168
|
+
setView={() => setView('single')}
|
|
169
|
+
selectedUserIds={selectedUserIds}
|
|
170
|
+
setSelectedUserIds={setSelectedUserIds}
|
|
171
|
+
users={users}
|
|
172
|
+
message={message}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
) : (
|
|
176
|
+
<CrudUserSingle
|
|
177
|
+
loading={loading}
|
|
178
|
+
setLoading={setLoading}
|
|
179
|
+
selectedUser={selectedUser}
|
|
180
|
+
setView={() => setView('list')}
|
|
181
|
+
refreshSelectedUser={refreshSelectedUser}
|
|
182
|
+
setUser={setUser}
|
|
183
|
+
fetchUsers={fetchUsers}
|
|
184
|
+
formatDate={formatDate}
|
|
185
|
+
setSelectedSingleItemId={setSelectedSingleItemId}
|
|
186
|
+
/>
|
|
187
|
+
)}
|
|
188
|
+
</div>
|
|
189
|
+
</CrudLayout>
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export default ManageUsers;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.crud-page {
|
|
2
|
+
.crud-list-cont {
|
|
3
|
+
.crud-list-header {
|
|
4
|
+
text-align: right;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.crud-list-controls {
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: space-between;
|
|
10
|
+
align-items: center;
|
|
11
|
+
margin-bottom: 20px;
|
|
12
|
+
|
|
13
|
+
.controls-left-col {
|
|
14
|
+
display: flex;
|
|
15
|
+
gap: 20px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.controls-right-col {
|
|
19
|
+
display: flex;
|
|
20
|
+
gap: 20px;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {createSlice, createAsyncThunk, createAction} from '@reduxjs/toolkit';
|
|
2
|
+
import { getAuthToken, getAuthUser, setAuthToken, setAuthUser, removeAuthToken, removeAuthUser } from '@gnar-engine/js-client/src/storage';
|
|
3
|
+
import gnarEngine from '@gnar-engine/js-client';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const login = createAsyncThunk('auth/login', async ({username, password}) => {
|
|
7
|
+
|
|
8
|
+
let response;
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
response = await gnarEngine.user.authenticate(username, password);;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
response = error.response;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return response;
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
export const logout = createAction('auth/logout');
|
|
20
|
+
|
|
21
|
+
export const authSlice = createSlice({
|
|
22
|
+
name: 'auth',
|
|
23
|
+
initialState: {
|
|
24
|
+
authUser: getAuthUser() ? JSON.parse(getAuthUser()) : null,
|
|
25
|
+
accessToken: getAuthToken() ? getAuthToken() : '',
|
|
26
|
+
authLoading: false,
|
|
27
|
+
authError: ''
|
|
28
|
+
},
|
|
29
|
+
reducers: {
|
|
30
|
+
},
|
|
31
|
+
extraReducers: builder => {
|
|
32
|
+
builder
|
|
33
|
+
.addCase(login.pending, (state, action) => {
|
|
34
|
+
state.authLoading = true;
|
|
35
|
+
state.authError = '';
|
|
36
|
+
})
|
|
37
|
+
.addCase(login.fulfilled, (state, action) => {
|
|
38
|
+
state.authLoading = false;
|
|
39
|
+
state.authError = action.payload.data?.error ? action.payload.data.message : '';
|
|
40
|
+
|
|
41
|
+
if (action.payload.token) {
|
|
42
|
+
state.accessToken = action.payload.token;
|
|
43
|
+
state.authUser = action.payload.user;
|
|
44
|
+
|
|
45
|
+
// store in local storage
|
|
46
|
+
setAuthToken(action.payload.token);
|
|
47
|
+
setAuthUser(JSON.stringify(action.payload.user));
|
|
48
|
+
|
|
49
|
+
// redirect to portal
|
|
50
|
+
window.location.href= '/portal';
|
|
51
|
+
} else {
|
|
52
|
+
// Handle error case
|
|
53
|
+
console.error('Login failed:', action.payload);
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
.addCase(logout, (state, action) => {
|
|
57
|
+
// Clear auth state
|
|
58
|
+
state.authUser = '';
|
|
59
|
+
state.accessToken = '';
|
|
60
|
+
|
|
61
|
+
// Remove from local storage
|
|
62
|
+
removeAuthToken();
|
|
63
|
+
removeAuthUser();
|
|
64
|
+
|
|
65
|
+
// Redirect to login page
|
|
66
|
+
window.location.href = '/login';
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
export default authSlice;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
|
|
2
|
+
/* vars */
|
|
3
|
+
|
|
4
|
+
@green-1: #479E78;
|
|
5
|
+
@dark-grey-1: #434343;
|
|
6
|
+
@mid-grey-1: #73768C;
|
|
7
|
+
@orange-1: #E8896D;
|
|
8
|
+
@orange-2: #EFA12C;
|
|
9
|
+
@dark-1: #3C5063;
|
|
10
|
+
@grey-light-1: #F6F8F9;
|
|
11
|
+
@grey-mid-1: #E4E4E4;
|
|
12
|
+
@grey-dark-1: #B3B3B3;
|
|
13
|
+
@white: #FFFFFF;
|
|
14
|
+
@red-1: #c73939;
|
|
15
|
+
@red-2: #ffeeee;
|
|
16
|
+
@green-2: #359E59;
|
|
17
|
+
|
|
18
|
+
@content-width: 1550px;
|
|
19
|
+
|
|
20
|
+
/* Fonts */
|
|
21
|
+
|
|
22
|
+
// @import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
|
|
23
|
+
|
|
24
|
+
body {
|
|
25
|
+
font-family: ubuntu, sans-serif;
|
|
26
|
+
color: @dark-1;
|
|
27
|
+
font-size: 14px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* Global styles */
|
|
31
|
+
|
|
32
|
+
h1 {
|
|
33
|
+
margin-top: 0px;
|
|
34
|
+
font-size: 28px;
|
|
35
|
+
font-weight: 600;
|
|
36
|
+
}
|
|
37
|
+
h2 {
|
|
38
|
+
font-size: 15px;
|
|
39
|
+
font-weight: 500;
|
|
40
|
+
}
|
|
41
|
+
body {
|
|
42
|
+
margin: 0px;
|
|
43
|
+
|
|
44
|
+
&, #root {
|
|
45
|
+
min-height: 100vh;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.separator {
|
|
50
|
+
margin-top: 20px;
|
|
51
|
+
margin-bottom: 20px;
|
|
52
|
+
height: 0px;
|
|
53
|
+
border-top: 1px solid @grey-mid-1;
|
|
54
|
+
}
|
|
55
|
+
.content-wrap {
|
|
56
|
+
display: flex;
|
|
57
|
+
justify-content: center;
|
|
58
|
+
}
|
|
59
|
+
.content {
|
|
60
|
+
width: 100%;
|
|
61
|
+
max-width: @content-width;
|
|
62
|
+
margin-left: auto;
|
|
63
|
+
margin-right: auto;
|
|
64
|
+
padding-left: 20px;
|
|
65
|
+
padding-right: 20px;
|
|
66
|
+
}
|
|
67
|
+
.instruction {
|
|
68
|
+
font-size: 12px;
|
|
69
|
+
margin-top: 10px;
|
|
70
|
+
margin-bottom: 10px;
|
|
71
|
+
}
|
|
72
|
+
.flex-row {
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-direction: row;
|
|
75
|
+
justify-content: space-between;
|
|
76
|
+
gap: 20px;
|
|
77
|
+
}
|
|
78
|
+
.flex-row-end{
|
|
79
|
+
align-items: flex-end;
|
|
80
|
+
}
|
|
81
|
+
.form-cont {
|
|
82
|
+
width: 100%;
|
|
83
|
+
margin-bottom: 30px;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.full-width-select-cont,
|
|
87
|
+
.full-width-select-cont .custom-select {
|
|
88
|
+
min-width: 100%;
|
|
89
|
+
}
|
|
90
|
+
.flex-row-select-cont {
|
|
91
|
+
min-width: 100%;
|
|
92
|
+
display: flex;
|
|
93
|
+
flex-direction: row;
|
|
94
|
+
justify-content: space-between;
|
|
95
|
+
gap: 20px;
|
|
96
|
+
|
|
97
|
+
.custom-select {
|
|
98
|
+
width: 100%;
|
|
99
|
+
max-width: unset;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.flex-row-checkbox-cont {
|
|
104
|
+
min-width: 100%;
|
|
105
|
+
display: flex;
|
|
106
|
+
flex-direction: row;
|
|
107
|
+
justify-content: space-between;
|
|
108
|
+
gap: 20px;
|
|
109
|
+
|
|
110
|
+
label {
|
|
111
|
+
display: inline-block;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.flex-row-buttons-cont {
|
|
116
|
+
display: flex;
|
|
117
|
+
flex-direction: row;
|
|
118
|
+
justify-content: flex-end;
|
|
119
|
+
gap: 20px;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.button {
|
|
123
|
+
&.button-loading {
|
|
124
|
+
background: @grey-mid-1 !important;
|
|
125
|
+
cursor: not-allowed !important;
|
|
126
|
+
|
|
127
|
+
&:disabled {
|
|
128
|
+
cursor: not-allowed;
|
|
129
|
+
opacity: 0.5;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.card {
|
|
135
|
+
background: @white;
|
|
136
|
+
border: 1px solid @grey-mid-1;
|
|
137
|
+
border-radius: 10px;
|
|
138
|
+
margin-top: 20px;
|
|
139
|
+
box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1);
|
|
140
|
+
|
|
141
|
+
.card-header {
|
|
142
|
+
width: 100%;
|
|
143
|
+
background-color: @dark-grey-1;
|
|
144
|
+
color: @white;
|
|
145
|
+
border-top-left-radius: 10px;
|
|
146
|
+
border-top-right-radius: 10px;
|
|
147
|
+
display: flex;
|
|
148
|
+
justify-content: space-between;
|
|
149
|
+
|
|
150
|
+
h2 {
|
|
151
|
+
padding: 20px;
|
|
152
|
+
margin: 0px;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.card-content {
|
|
157
|
+
padding: 20px;
|
|
158
|
+
}
|
|
159
|
+
}
|