diff options
-rw-r--r-- | cypress/e2e/event.cy.ts | 2 | ||||
-rw-r--r-- | cypress/support/commands.ts | 2 | ||||
-rwxr-xr-x | public/css/style.css | 3 | ||||
-rw-r--r-- | src/util/validation.ts | 30 | ||||
-rwxr-xr-x | views/event.handlebars | 2 | ||||
-rwxr-xr-x | views/eventgroup.handlebars | 16 | ||||
-rwxr-xr-x | views/partials/eventForm.handlebars | 5 | ||||
-rw-r--r-- | views/partials/eventGroupForm.handlebars | 5 |
8 files changed, 50 insertions, 15 deletions
diff --git a/cypress/e2e/event.cy.ts b/cypress/e2e/event.cy.ts index d5366e2..eeaa629 100644 --- a/cypress/e2e/event.cy.ts +++ b/cypress/e2e/event.cy.ts @@ -217,7 +217,7 @@ describe("Events", () => { cy.createGroup({ eventGroupName: "Test Group", eventGroupDescription: "Test Group Description", - eventGroupURL: "testgroup", + eventGroupURL: "https://example.com", hostName: "Test Host", creatorEmail: "test@example.com", }); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index eadcd20..6757255 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -46,7 +46,7 @@ declare namespace Cypress { hostName: string; creatorEmail: string; }, - isPublic: boolean, + isPublic?: boolean, ): Chainable<Subject>; } } diff --git a/public/css/style.css b/public/css/style.css index 9a81967..3321090 100755 --- a/public/css/style.css +++ b/public/css/style.css @@ -441,7 +441,8 @@ ul#sidebar__nav a { flex-wrap: wrap; } -#event__actions #editEvent { +#event__actions #editEvent, +#event__actions #editGroup { width: 100%; margin-top: 16px; } diff --git a/src/util/validation.ts b/src/util/validation.ts index b9a0c8a..a3bea63 100644 --- a/src/util/validation.ts +++ b/src/util/validation.ts @@ -73,6 +73,20 @@ const validateEmail = (email: string) => { return re.test(email); }; +// From https://stackoverflow.com/a/43467144 +const validateUrl = (url: string) => { + if (!url) { + return false; + } + let validUrl; + try { + validUrl = new URL(url); + } catch (_) { + return false; + } + return validUrl.protocol === "http:" || validUrl.protocol === "https:"; +}; + export const validateEventTime = (start: Date, end: Date): Error | boolean => { if (moment(start).isAfter(moment(end))) { return { @@ -195,6 +209,14 @@ export const validateEventData = ( }); } } + if (validatedData.eventURL) { + if (!validateUrl(validatedData.eventURL)) { + errors.push({ + message: "Event link is invalid.", + field: "eventURL", + }); + } + } return { data: validatedData, @@ -226,6 +248,14 @@ export const validateGroupData = ( }); } } + if (groupData.eventGroupURL) { + if (!validateUrl(groupData.eventGroupURL)) { + errors.push({ + message: "Group link is invalid.", + field: "eventGroupURL", + }); + } + } const validatedData: ValidatedEventGroupData = { ...groupData, diff --git a/views/event.handlebars b/views/event.handlebars index cd1645a..1b1022e 100755 --- a/views/event.handlebars +++ b/views/event.handlebars @@ -11,7 +11,7 @@ </div> <div class="col-lg-3 ml-2 edit-buttons"> {{#if editingEnabled}} - <button type="button" id="editEvent" class="button button--primary" {{#if eventHasConcluded}}disabled{{/if}} data-event-id="{{eventData.id}}" data-toggle="modal" data-target="#editModal"><i class="fas fa-edit"></i> Edit event</button> + <button type="button" id="editEvent" class="button button--primary ml-auto d-block" {{#if eventHasConcluded}}disabled{{/if}} data-event-id="{{eventData.id}}" data-toggle="modal" data-target="#editModal"><i class="fas fa-edit"></i> Edit event</button> {{/if}} </div> </div> diff --git a/views/eventgroup.handlebars b/views/eventgroup.handlebars index 8fbedbc..9658b60 100755 --- a/views/eventgroup.handlebars +++ b/views/eventgroup.handlebars @@ -10,9 +10,7 @@ </div> <div class="col-lg-2 ml-2 edit-buttons"> {{#if editingEnabled}} - <button type="button" id="editGroup" class="button button--primary text-nowrap" data-event-id="{{eventGroupData.id}}" data-toggle="modal" data-target="#editModal"><i class="fas fa-edit"></i> Edit group</button> - {{else}} - <button type="button" id="editGroup" class="button button--primary text-nowrap" data-event-id="{{eventGroupData.id}}" data-toggle="modal" data-target="#editTokenModal"><i class="fas fa-edit"></i> Edit group</button> + <button type="button" id="editGroup" class="button button--primary text-nowrap ml-auto d-block" data-event-id="{{eventGroupData.id}}" data-toggle="modal" data-target="#editModal"><i class="fas fa-edit"></i> Edit group</button> {{/if}} </div> </div> @@ -85,6 +83,10 @@ <i class="fas fa-download"></i> Export as ICS </button> </div> + + {{#unless editingEnabled}} + <button type="button" id="editGroup" class="button button--outline-secondary button--sm" data-event-id="{{eventGroupData.id}}" data-toggle="modal" data-target="#editTokenModal"><i class="fas fa-edit"></i> Switch to editing mode</button> + {{/unless}} </aside> </div> @@ -103,12 +105,12 @@ </tr> </table> </div> - + </div> {{/if}} <div class="card mb-4" id="eventDescription"> - <h5 class="card-header">About</h5> + <h5 class="card-header">About</h5> <div class="card-body"> {{{parsedDescription}}} </div> @@ -268,7 +270,7 @@ window.groupData = {{{ json jsonData }}}; if (urlParams.has('show_edit')) { $('#editModal').modal('show'); - url.searchParams.delete('show_edit'); + url.searchParams.delete('show_edit'); history.replaceState(history.state, '', url.href); } @@ -339,4 +341,4 @@ window.groupData = {{{ json jsonData }}}; }); </script> -</main>
\ No newline at end of file +</main> diff --git a/views/partials/eventForm.handlebars b/views/partials/eventForm.handlebars index 161f44b..6fbbbf0 100755 --- a/views/partials/eventForm.handlebars +++ b/views/partials/eventForm.handlebars @@ -39,7 +39,8 @@ <div class="form-group"> <label for="eventURL">Link</label> <div class="form-group "> - <input type="url" class="form-control" id="eventURL" name="eventURL" placeholder="For tickets or another event page (optional)." x-model="data.eventURL" > + <input type="url" class="form-control" id="eventURL" name="eventURL" placeholder="https://example.com" x-model="data.eventURL"> + <small class="form-text">For tickets or another event page (optional).</small> </div> </div> <div class="form-group"> @@ -106,7 +107,7 @@ <option></option> <template x-for="group in data.groups"> <option :value="group.id" x-text="group.name"></option> - </template> + </template> </select> </div> <button type="button" class="button button--outline-primary w-100 text-center" x-on:click="manualGroupInputVisible = !manualGroupInputVisible"> diff --git a/views/partials/eventGroupForm.handlebars b/views/partials/eventGroupForm.handlebars index 284343f..5536e49 100644 --- a/views/partials/eventGroupForm.handlebars +++ b/views/partials/eventGroupForm.handlebars @@ -10,7 +10,8 @@ </div> <div class="form-group"> <label for="eventGroupURL">Link</label> - <input type="url" class="form-control" id="eventGroupURL" name="eventGroupURL" placeholder="For tickets or a page with more information (optional)." x-model="data.eventGroupURL"> + <input type="url" class="form-control" id="eventGroupURL" name="eventGroupURL" placeholder="https://example.com" x-model="data.eventGroupURL"> + <small class="form-text">For tickets or a page with more information (optional).</small> </div> <div class="form-group"> <label for="hostName">Host or organisation name</label> @@ -57,4 +58,4 @@ </ul> </div> </div> -</div>
\ No newline at end of file +</div> |