Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create invitations for closed registrations #233

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Send unix timestamp
  • Loading branch information
thomiceli committed Mar 20, 2024
commit 0e228d0068a2372140e6dcd23499d29fc950c669
17 changes: 4 additions & 13 deletions internal/web/admin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package web

import (
"fmt"
"github.com/labstack/echo/v4"
"github.com/thomiceli/opengist/internal/actions"
"github.com/thomiceli/opengist/internal/config"
Expand Down Expand Up @@ -203,18 +202,10 @@ func adminInvitationsCreate(ctx echo.Context) error {
if err != nil {
nbMax = 10
}
expiresAt := ctx.FormValue("expiresAt")
var expiresAtUnix int64
fmt.Println(expiresAt)
if expiresAt == "" {
expiresAtUnix = time.Now().Add(7 * 24 * time.Hour).Unix()
} else {
parsedDate, err := time.Parse("2006-01-02T15:04", expiresAt)
if err != nil {
return errorRes(400, "Invalid date format", err)
}
parsedDateUTC := time.Date(parsedDate.Year(), parsedDate.Month(), parsedDate.Day(), parsedDate.Hour(), parsedDate.Minute(), 0, 0, time.Local)
expiresAtUnix = parsedDateUTC.Unix()

expiresAtUnix, err := strconv.ParseInt(ctx.FormValue("expiredAtUnix"), 10, 64)
if err != nil {
expiresAtUnix = time.Now().Unix() + 604800 // 1 week
}

invitation := &db.Invitation{
Expand Down
16 changes: 16 additions & 0 deletions public/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ document.addEventListener('DOMContentLoaded', () => {
e.innerHTML = dayjs.unix(parseInt(e.innerHTML)).format('DD/MM/YYYY HH:mm');
});

document.querySelectorAll('form').forEach((form: HTMLFormElement) => {
form.onsubmit = () => {
form.querySelectorAll('input[type=datetime-local]').forEach((input: HTMLInputElement) => {
console.log(dayjs(input.value).unix());
const hiddenInput = document.createElement('input');
hiddenInput.type = 'hidden';
hiddenInput.name = 'expiredAtUnix'
hiddenInput.value = dayjs(input.value).unix().toString();
form.appendChild(hiddenInput);
});
return true;
};
})



const rev = document.querySelector<HTMLElement>('.revision-text');
if (rev) {
const fullRev = rev.innerHTML;
Expand Down
Loading