From 339166a5094b09dd9f2e42bdacdd8dd601bc2d2b Mon Sep 17 00:00:00 2001
From: ChrisChrome <chris@chrischro.me>
Date: Sat, 21 Dec 2024 02:36:06 -0700
Subject: [PATCH] Fix 

---
 public/assets/js/admin/dashboard.js |  1 -
 views/admin/create.ejs              | 40 ++++++++++++++++++++++++++
 views/admin/edit.ejs                | 44 ++++++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/public/assets/js/admin/dashboard.js b/public/assets/js/admin/dashboard.js
index c7917aa..c5b076b 100644
--- a/public/assets/js/admin/dashboard.js
+++ b/public/assets/js/admin/dashboard.js
@@ -27,7 +27,6 @@ fetch('/api/v1/info')
 					<td>${reasonsFlagNames}</td>
 					<td>${ban.moderator || 'N/A'}</td>
 					<td>${banTimestamp}</td>
-					<td>${expiresTimestamp}</td>
 					<td style="color: ${ban.expiresTimestamp && new Date(ban.expiresTimestamp) < new Date() ? 'green' : ''};">
 						${expiresTimestamp}
 					</td>
diff --git a/views/admin/create.ejs b/views/admin/create.ejs
index 0046314..5438696 100644
--- a/views/admin/create.ejs
+++ b/views/admin/create.ejs
@@ -54,7 +54,47 @@
 						<div class="mb-3">
 							<label for="expiresTimestamp" class="form-label">Expires (Optional)</label>
 							<input type="datetime-local" class="form-control" id="expiresTimestamp" name="expiresTimestamp">
+							<button type="button" class="btn btn-secondary mt-2" id="setNowButton">Now</button>
+							<script>
+								document.getElementById('setNowButton').addEventListener('click', function() {
+									const expiresTimestamp = document.getElementById('expiresTimestamp');
+									const now = new Date();
+									const year = now.getFullYear();
+									const month = String(now.getMonth() + 1).padStart(2, '0');
+									const day = String(now.getDate()).padStart(2, '0');
+									const hours = String(now.getHours()).padStart(2, '0');
+									const minutes = String(now.getMinutes()).padStart(2, '0');
+									const formattedNow = `${year}-${month}-${day}T${hours}:${minutes}`;
+									expiresTimestamp.value = formattedNow;
+									expiresTimestamp.disabled = false;
+									document.getElementById('neverExpires').checked = false;
+								});
+							</script>
+							<div class="form-check mt-2">
+								<input class="form-check-input" type="checkbox" id="neverExpires" name="neverExpires">
+								<label class="form-check-label" for="neverExpires">Never</label>
+							</div>
 						</div>
+						<script>
+							document.getElementById('neverExpires').addEventListener('change', function() {
+								const expiresTimestamp = document.getElementById('expiresTimestamp');
+								if (this.checked) {
+									expiresTimestamp.value = '';
+									expiresTimestamp.disabled = true;
+									expiresTimestamp.setAttribute('data-null', 'true');
+								} else {
+									expiresTimestamp.disabled = false;
+									expiresTimestamp.removeAttribute('data-null');
+								}
+							});
+
+							document.getElementById('banForm').addEventListener('submit', function(event) {
+								const expiresTimestamp = document.getElementById('expiresTimestamp');
+								if (expiresTimestamp.getAttribute('data-null') === 'true') {
+									expiresTimestamp.value = null;
+								}
+							});
+						</script>
 						
 						<button type="submit" class="btn btn-primary w-100">Submit</button>
 					</form>
diff --git a/views/admin/edit.ejs b/views/admin/edit.ejs
index 2f2d62d..2548b39 100644
--- a/views/admin/edit.ejs
+++ b/views/admin/edit.ejs
@@ -53,8 +53,50 @@
 						</div>
 						<div class="mb-3">
 							<label for="expiresTimestamp" class="form-label">Expires (Optional)</label>
-							<input type="datetime-local" class="form-control" id="expiresTimestamp" name="expiresTimestamp" value="<%= ban.expiresTimestamp %>">
+							<input type="datetime-local" class="form-control" id="expiresTimestamp" name="expiresTimestamp" value="<%= ban.expiresTimestamp %>" <%= ban.expiresTimestamp ? '' : 'disabled' %>>
+							<button type="button" class="btn btn-secondary mt-2" id="setNowButton">Now</button>
+							<script>
+								document.getElementById('setNowButton').addEventListener('click', function() {
+									const expiresTimestamp = document.getElementById('expiresTimestamp');
+									const now = new Date();
+									const year = now.getFullYear();
+									const month = String(now.getMonth() + 1).padStart(2, '0');
+									const day = String(now.getDate()).padStart(2, '0');
+									const hours = String(now.getHours()).padStart(2, '0');
+									const minutes = String(now.getMinutes()).padStart(2, '0');
+									const formattedNow = `${year}-${month}-${day}T${hours}:${minutes}`;
+									expiresTimestamp.value = formattedNow;
+									expiresTimestamp.disabled = false;
+									document.getElementById('neverExpires').checked = false;
+								});
+
+							</script>
+							<div class="form-check mt-2">
+								<input class="form-check-input" type="checkbox" id="neverExpires" name="neverExpires" <%= ban.expiresTimestamp ? '' : 'checked' %>>
+								<label class="form-check-label" for="neverExpires">Never</label>
+							</div>
 						</div>
+
+						<script>
+							document.getElementById('neverExpires').addEventListener('change', function() {
+								const expiresTimestamp = document.getElementById('expiresTimestamp');
+								if (this.checked) {
+									expiresTimestamp.value = '';
+									expiresTimestamp.disabled = true;
+									expiresTimestamp.setAttribute('data-null', 'true');
+								} else {
+									expiresTimestamp.disabled = false;
+									expiresTimestamp.removeAttribute('data-null');
+								}
+							});
+
+							document.getElementById('banForm').addEventListener('submit', function(event) {
+								const expiresTimestamp = document.getElementById('expiresTimestamp');
+								if (expiresTimestamp.getAttribute('data-null') === 'true') {
+									expiresTimestamp.value = null;
+								}
+							});
+						</script>
 						
 						<button type="submit" class="btn btn-primary w-100">Submit</button>
 					</form>
