Skip to content

Commit eab36a0

Browse files
committed
Single commission view
1 parent f8b3cfc commit eab36a0

3 files changed

Lines changed: 107 additions & 2 deletions

File tree

frontend/pages/commission.ejs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<%- include('head.ejs') %>
2+
<img src="<%= tenant.logo %>" alt="<%= tenant.name %>">
3+
<h1><%= title %></h1>
4+
<% if (commission.locked) { %><p>This commission is locked from editing.</p><% } %>
5+
<table>
6+
<tr>
7+
<th>Status</th>
8+
<td><%= commission.status %></td>
9+
</tr>
10+
<tr>
11+
<th>Owner</th>
12+
<td><%= commission.user %><%= (commission.user === session[vars.userId]) ? ' (you)' : '' %></td>
13+
</tr>
14+
<% if (commission.amount !== null) { %>
15+
<tr>
16+
<th>Amount</th>
17+
<td><%= commission.amount %> <%= commission.currency %></td>
18+
</tr>
19+
<% } %>
20+
<% if (commission.date !== null) { %>
21+
<tr>
22+
<th>Date</th>
23+
<td><%= new Date(commission.date).toLocaleString() %></td>
24+
</tr>
25+
<% } %>
26+
</table>
27+
<table>
28+
<% for (const field of fields) { %>
29+
<tr>
30+
<th><%= field.label %></th>
31+
<% switch (field.type) {
32+
case 'number': %>
33+
<td><%= (commission.fields[field.id] === null) ? '-' : Number(commission.fields[field.id]) %></td>
34+
<% break;
35+
case 'date': %>
36+
<td><%= isNaN(new Date(commission.fields[field.id]).getTime()) ? '-' : new Date(commission.fields[field.id]).toLocaleString() %></td>
37+
<% break;
38+
case 'checkbox': %>
39+
<td><%= commission.fields[field.id] ? 'Yes': 'No' %></td>
40+
<% break;
41+
case 'radio': %>
42+
<td><%= commission.fields[field.id] || '-' %></td>
43+
<% break;
44+
case 'select': %>
45+
<td><%= commission.fields[field.id] || '-' %></td>
46+
<% break;
47+
default: %>
48+
<td><%= commission.fields[field.id] || '-' %></td>
49+
<% break;
50+
} %>
51+
</tr>
52+
<% } %>
53+
</table>
54+
<div class="buttons">
55+
<a class="button" href="<%= tenant.domain %><%= tenant.path %>">Back</a>
56+
<% if (!commission.locked || (role !== 'user')) { %>
57+
<a class="button" href="<%= tenant.domain %><%= tenant.path %>/<%= commission.id %>/edit">Edit</a>
58+
<% } %>
59+
</div>
60+
<%- include('foot.ejs') %>

frontend/public/styles.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ main {
254254
}
255255
}
256256

257-
.inner:has(.commissions) {
257+
.inner:has(.commissions),
258+
.inner:has(table) {
258259
overflow: scroll;
259260
}
260261

@@ -329,6 +330,17 @@ main {
329330
transition: 0.25s;
330331
}
331332
}
333+
334+
table {
335+
display: flex;
336+
padding: 12.5px 0;
337+
background: #161616;
338+
border-radius: 10px;
339+
text-align: left;
340+
border-spacing: 20px 4px;
341+
width: -webkit-fill-available;
342+
max-width: 500px;
343+
}
332344
}
333345

334346
@keyframes out {

index.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,40 @@ app.put('/sync', async (req, res) => {
204204
return res.status(500).json({ status: 'error', message: 'An error occurred while processing your request. Please try again later.' });
205205
};
206206
};
207-
res.status(200).json({ status: 'success', message: 'Your commissions were synchronized successfully.' });
207+
return res.status(200).json({ status: 'success', message: 'Your commissions were synchronized successfully.' });
208+
});
209+
210+
app.get('/:id', async (req, res) => {
211+
if (!on) return res.render('off', { tenant, title: 'Activation' });
212+
if (!req.session) return res.render('session', { tenant, title: 'Session' });
213+
if (!tenant.slug || !tenant.name || !tenant.domain) return res.render('tenant', { tenant, title: 'Configuration' });
214+
if (tenant.auth && tenant.auth.enabled && vars.userId && !req.session[vars.userId]) return res.render('auth', { tenant, title: 'Authenticate' });
215+
req.session[vars.commissions] = (req.session[vars.commissions] || []).map(commission => {
216+
if (!commission.id || !commission.user || (commission.date ? isNaN(new Date(commission.date).getTime()) : false) || (typeof commission.status !== 'string') || (typeof commission.tasks !== 'object')) return null;
217+
return {
218+
id: commission.id,
219+
user: commission.user,
220+
amount: commission.amount ? Number(commission.amount) : null,
221+
currency: commission.currency ? String(commission.currency) : 'USD',
222+
date: commission.date ? new Date(commission.date) : null,
223+
status: commission.status,
224+
fields: fields.reduce((acc, field) => {
225+
acc[field.id] = (commission.fields && (commission.fields[field.id] !== undefined)) ? commission.fields[field.id] : null;
226+
return acc;
227+
}, {}),
228+
tasks: (commission.tasks || []).map(task => {
229+
return {
230+
done: task.done || false,
231+
content: task.content ? String(task.content) : ''
232+
}
233+
}),
234+
locked: commission.locked || false
235+
};
236+
}).filter(commission => commission !== null);
237+
if (getUserRole(req.session) === 'user') req.session[vars.commissions] = req.session[vars.commissions].filter(commission => commission.user === req.session[vars.userId]);
238+
const commission = (req.session[vars.commissions] || []).find(commission => (String(commission.id) === String(req.params.id)) && (commission.user === req.session[vars.userId]));
239+
if (!commission) return res.status(404).render('error', { tenant, title: 'Not Found', message: 'The requested commission was not found.' });
240+
return res.render('commission', { tenant, title: `Commission ${commission.id}`, session: req.session, vars, fields, role: getUserRole(req.session), commission });
208241
});
209242

210243
app.use((req, res) => {

0 commit comments

Comments
 (0)