Skip to content

Commit 552c643

Browse files
committed
Show expiration days
1 parent 03d2358 commit 552c643

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/OrchardCoreContrib.Contents/Views/Content_ShareDraftButton.cshtml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,37 @@
3030
<button id="copyButton" type="button" class="btn btn-outline-secondary mt-2" onclick="copyUrl()">
3131
Copy to Clipboard
3232
</button>
33-
<p class="text-muted mt-2">Valid for 30 days</p>
33+
<p class="text-muted mt-2">
34+
Expires in <span id="expiryCountdown"></span>
35+
</p>
3436
</div>
3537
</div>
3638
</div>
3739
</div>
3840

3941
<script at="Foot">
42+
const copyButton = document.getElementById('copyButton');
43+
const expireyCountdown = document.getElementById("expiryCountdown");
44+
45+
const expiryDate = new Date("@Model.Link.ExpirationUtc.ToString("o")");
46+
const now = new Date();
47+
const diff = expiryDate - now;
48+
49+
if (diff <= 0) {
50+
expireyCountdown.parentElement.setAttribute('class', 'text-danger mt-2')
51+
expireyCountdown.parentElement.innerText = "Expired";
52+
copyButton.disabled = true;
53+
}
54+
else {
55+
const days = Math.floor(diff / (1000*60*60*24));
56+
57+
expireyCountdown.innerText = `${days} days`;
58+
}
59+
4060
function copyUrl() {
4161
const link = document.getElementById('linkInput').value;
4262
navigator.clipboard.writeText(link);
4363
44-
var copyButton = document.getElementById('copyButton');
4564
copyButton.setAttribute('class', 'btn btn-secondary mt-2');
4665
copyButton.innerText = 'Copied!';
4766
}

0 commit comments

Comments
 (0)