Submit status changes to the backend
This commit is contained in:
parent
45e2665997
commit
1d59535eb6
@ -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',
|
||||||
|
@ -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) => {
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
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>>([]);
|
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) => {
|
||||||
@ -28,13 +29,19 @@ export default function guestsTable() {
|
|||||||
|
|
||||||
|
|
||||||
const handleInviteGuest = (e: React.MouseEvent<HTMLElement>) => {
|
const handleInviteGuest = (e: React.MouseEvent<HTMLElement>) => {
|
||||||
fetch("http://localhost:3001/guests/bulk-status-change.json", { method: 'POST', body: JSON.stringify({ status: "Invited", guest_ids: [e.currentTarget.getAttribute('data-guest-id')] }) })
|
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((response) => console.log(response.json()))
|
.then((response) => console.log(response.json()))
|
||||||
.catch((error) => console.error(error));
|
.catch((error) => console.error(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
guests.length === 0 && loadGuests();
|
guests.length === 0 && loadGuests();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user