Merge pull request 'Feature: Mark guests as invited' (#60) from guest-status-changes into main
Some checks failed
Build Nginx-based docker image / build-static-assets (push) Failing after 41s
Check usage of free licenses / build-static-assets (push) Successful in 2m22s
Playwright Tests / test (push) Has been cancelled

Reviewed-on: #60
This commit is contained in:
bustikiller 2024-10-27 18:28:22 +00:00
commit a4178038ad
3 changed files with 34 additions and 5 deletions

View File

@ -7,6 +7,13 @@ export const formatCurrency = (amount: number) => {
}); });
}; };
export const getCsrfToken = () => {
return document.cookie
.split("; ")
.find((row) => row.startsWith("csrf-token"))
?.split("=")[1] || 'unknown';
}
export const formatDateToLocal = ( export const formatDateToLocal = (
dateStr: string, dateStr: string,
locale: string = 'en-US', locale: string = 'en-US',

View File

@ -44,7 +44,7 @@ export default function AffinityGroupsTree() {
if (nodes.length > 0) { if (nodes.length > 0) {
return; return;
} }
fetch("http://localhost:3001/groups.json") fetch("/api/groups.json")
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
setNodes(data.data.map((record: any) => { setNodes(data.data.map((record: any) => {

View File

@ -2,11 +2,14 @@
import clsx from 'clsx'; import clsx from 'clsx';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Guest } from '@/app/lib/definitions'; import { Guest } from '@/app/lib/definitions';
import { getCsrfToken } from '@/app/lib/utils';
export default function guestsTable() { export default function guestsTable() {
const [guests, setGuests] = useState<Array<Guest>>([]);
function loadGuests() { function loadGuests() {
fetch("http://localhost:3001/guests.json") fetch("/api/guests.json")
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
setGuests(data.data.map((record: any) => { setGuests(data.data.map((record: any) => {
@ -21,9 +24,22 @@ export default function guestsTable() {
}, (error) => { }, (error) => {
return []; return [];
}); });
} };
const [guests, setGuests] = useState<Array<Guest>>([]);
const handleInviteGuest = (e: React.MouseEvent<HTMLElement>) => {
fetch("/api/guests/bulk_update.json",
{
method: 'POST',
body: JSON.stringify({ properties: { status: "invited" }, guest_ids: [e.currentTarget.getAttribute('data-guest-id')] }),
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': getCsrfToken(),
}
})
.then(() => loadGuests())
.catch((error) => console.error(error));
}
guests.length === 0 && loadGuests(); guests.length === 0 && loadGuests();
@ -50,6 +66,7 @@ export default function guestsTable() {
<th scope="col" className="px-6 py-3"> <th scope="col" className="px-6 py-3">
Status Status
</th> </th>
<th>Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -79,6 +96,11 @@ export default function guestsTable() {
{guest.status} {guest.status}
</span> </span>
</td> </td>
<td>
{guest.status === 'Considered' && (<button data-guest-id={guest.id} onClick={handleInviteGuest} className="bg-blue-300 hover:bg-blue-500 text-white py-1 px-2 rounded">
Invite
</button>)}
</td>
</tr> </tr>
))} ))}
</tbody> </tbody>