Skip to content

Commit 482a39e

Browse files
committed
Commissions variable usage, commissions variable schema verification, user-facing commissions list
1 parent e42c1a7 commit 482a39e

3 files changed

Lines changed: 88 additions & 2 deletions

File tree

frontend/pages/user.ejs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,13 @@
1111
<div class="buttons">
1212
<a class="button" href="<%= tenant.domain %><%= tenant.path %>/create">New Commission</a>
1313
</div>
14+
<div class="commissions">
15+
<% session[vars.commissions].forEach(commission => { %>
16+
<div class="commission">
17+
<h2><%= commission.id %></h2>
18+
<p><%= commission.status.replaceAll('-', ' ').replace(/\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase() }) %></p>
19+
<a class="button" href="<%= tenant.domain %><%= tenant.path %>/<%= commission.id %>"><%= commission.locked ? 'View' : 'Edit' %></a>
20+
</div>
21+
<% }) %>
22+
</div>
1423
<%- include('foot.ejs') %>

frontend/public/styles.css

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,13 @@ main {
229229
display: flex;
230230
flex-direction: column;
231231
align-items: flex-start;
232-
justify-content: center;
232+
justify-content: flex-start;
233233
align-self: center;
234234
gap: 10px;
235235
width: 80%;
236236
max-width: 1000px;
237-
height: 100%;
237+
height: fit-content;
238+
max-height: 100%;
238239
position: relative;
239240
transition-timing-function: ease-in-out;
240241
opacity: 0;
@@ -244,6 +245,10 @@ main {
244245
}
245246
}
246247

248+
.inner:has(.commissions) {
249+
overflow: scroll;
250+
}
251+
247252
.inputField {
248253
display: flex;
249254
flex-direction: column;
@@ -261,6 +266,55 @@ main {
261266
opacity: 0;
262267
transition: 0.25s;
263268
}
269+
270+
.commissions {
271+
display: flex;
272+
flex-direction: column;
273+
align-items: flex-start;
274+
gap: 5px;
275+
width: -webkit-fill-available;
276+
max-width: 500px;
277+
margin-top: 10px;
278+
279+
.commission {
280+
display: flex;
281+
align-items: center;
282+
gap: 10px;
283+
width: -webkit-fill-available;
284+
justify-content: flex-start;
285+
position: relative;
286+
padding-left: 10px;
287+
288+
.button {
289+
margin-left: auto;
290+
width: fit-content;
291+
min-width: 35px;
292+
}
293+
294+
p {
295+
margin-right: 20px;
296+
}
297+
}
298+
299+
.commission::before {
300+
content: "";
301+
height: -webkit-fill-available;
302+
width: min(80%, 450px);
303+
background: transparent;
304+
border-top: 1px solid #ffffff;
305+
border-bottom: 1px solid #ffffff;
306+
position: absolute;
307+
margin-left: -50px;
308+
opacity: 0;
309+
transition: 0.25s;
310+
}
311+
312+
.commission:has(.button:hover)::before {
313+
margin-left: -10px;
314+
opacity: 1;
315+
transition: 0.25s;
316+
}
317+
}
264318
}
265319

266320
@keyframes out {

index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ app.get('/', async (req, res) => {
121121
if (!req.session) return res.render('session', { tenant, title: 'Session' });
122122
if (!tenant.slug || !tenant.name || !tenant.domain) return res.render('tenant', { tenant, title: 'Configuration' });
123123
if (tenant.auth && tenant.auth.enabled && vars.userId && !req.session[vars.userId]) return res.render('auth', { tenant, title: 'Authenticate' });
124+
req.session[vars.commissions] = (req.session[vars.commissions] || []).map(commission => {
125+
if (!commission.id || !commission.user || (commission.date ? isNaN(new Date(commission.date).getTime()) : false) || !['completed', 'in-progress', 'on-hold', 'cancelled'].some(status => commission.status.includes(status)) || (typeof commission.tasks !== 'object')) return null;
126+
return {
127+
id: commission.id,
128+
user: commission.user,
129+
amount: commission.amount ? Number(commission.amount) : null,
130+
currency: commission.currency ? String(commission.currency) : 'USD',
131+
date: commission.date ? new Date(commission.date) : null,
132+
status: commission.status,
133+
fields: fields.reduce((acc, field) => {
134+
acc[field.id] = (commission.fields && (commission.fields[field.id] !== undefined)) ? commission.fields[field.id] : null;
135+
return acc;
136+
}, {}),
137+
tasks: (commission.tasks || []).map(task => {
138+
return {
139+
done: task.done || false,
140+
content: task.content ? String(task.content) : ''
141+
}
142+
}),
143+
locked: commission.locked || false
144+
};
145+
}).filter(commission => commission !== null);
124146
switch (getUserRole(req.session)) {
125147
case 'admin':
126148
res.render('admin', { tenant, title: 'Admin View', session: req.session, vars });
@@ -129,6 +151,7 @@ app.get('/', async (req, res) => {
129151
res.render('dev', { tenant, title: 'Developer View', session: req.session, vars });
130152
break;
131153
default:
154+
req.session[vars.commissions] = req.session[vars.commissions].filter(commission => commission.user === req.session[vars.userId]);
132155
res.render('user', { tenant, title: '', session: req.session, vars, fields });
133156
break;
134157
};

0 commit comments

Comments
 (0)