Compare commits
8 Commits
7d22cf32af
...
707390f261
Author | SHA1 | Date | |
---|---|---|---|
![]() |
707390f261 | ||
a74ef0c8b6 | |||
87cf2d3bb2 | |||
5c1f8b0dbe | |||
24e60231d0 | |||
943da9c7e8 | |||
cc698102f2 | |||
87bd3fac4b |
119
app/[slug]/site/invitation/[id]/page.tsx
Normal file
119
app/[slug]/site/invitation/[id]/page.tsx
Normal file
@ -0,0 +1,119 @@
|
||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
||||
|
||||
'use client'
|
||||
|
||||
import { AbstractApi } from "@/app/api/abstract-api";
|
||||
import { Invitation, InvitationSerializer } from "@/app/lib/invitation";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { FloatLabel } from "primereact/floatlabel";
|
||||
import { Dropdown } from "primereact/dropdown";
|
||||
import { Guest, GuestSerializer, GuestStatus } from "@/app/lib/guest";
|
||||
import { Button } from "primereact/button";
|
||||
|
||||
type FormResponse = {
|
||||
attendance: GuestStatus;
|
||||
};
|
||||
|
||||
function GuestForm({ guest, idx }: { guest: Guest, idx: number }) {
|
||||
const [response, setResponse] = useState<FormResponse>({
|
||||
attendance: guest.status!
|
||||
});
|
||||
|
||||
const [pendingChanges, setPendingChanges] = useState(false);
|
||||
const [sending, setSending] = useState(false);
|
||||
|
||||
console.log('GuestForm response', response.attendance);
|
||||
|
||||
const attendanceOptions: { name: string, code: GuestStatus }[] = [
|
||||
{
|
||||
name: 'Attending',
|
||||
code: 'confirmed'
|
||||
},
|
||||
{
|
||||
name: 'Declined',
|
||||
code: 'declined'
|
||||
},
|
||||
{
|
||||
name: 'Tentative',
|
||||
code: 'tentative'
|
||||
}
|
||||
];
|
||||
|
||||
const api = new AbstractApi<Guest>();
|
||||
const serializer = new GuestSerializer();
|
||||
|
||||
const submitForm = () => {
|
||||
setSending(true);
|
||||
setPendingChanges(false);
|
||||
api.update(serializer, {
|
||||
id: guest.id!,
|
||||
status: response.attendance,
|
||||
}, () => setSending(false));
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
key={guest.id}
|
||||
className={`px-2 py-6 flex flex-col items-center ${idx !== 0 ? 'border-t border-gray-300' : ''}`}
|
||||
>
|
||||
<h2 className="m-2 text-xl font-semibold">{guest.name}</h2>
|
||||
|
||||
<Dropdown
|
||||
value={response.attendance}
|
||||
options={attendanceOptions}
|
||||
optionLabel="name"
|
||||
optionValue="code"
|
||||
className="rounded-md w-full max-w-xs border border-gray-300"
|
||||
checkmark={true}
|
||||
highlightOnSelect={false}
|
||||
onChange={(e) => {
|
||||
setPendingChanges(true);
|
||||
setResponse({ ...response, attendance: e.value })
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
label="Save"
|
||||
icon="pi pi-save"
|
||||
loading={sending}
|
||||
onClick={submitForm}
|
||||
disabled={!pendingChanges || sending}
|
||||
className="mt-4 max-w-xs"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function Page() {
|
||||
const params = useParams<{ slug: string, id: string }>()
|
||||
|
||||
const [invitation, setInvitation] = useState<Invitation>();
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem('slug', params.slug);
|
||||
|
||||
const api = new AbstractApi<Invitation>();
|
||||
const serializer = new InvitationSerializer();
|
||||
|
||||
api.get(serializer, params.id, (invitation: Invitation) => {
|
||||
setInvitation(invitation);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center">
|
||||
<h1 className="text-2xl font-bold mb-4">Invitation</h1>
|
||||
{invitation ? (
|
||||
<div>
|
||||
<p>We have reserved {invitation.guests.length} seats in your honor. Please, confirm attendance submitting the following form:</p>
|
||||
{invitation.guests.map((guest, idx) => (
|
||||
<GuestForm key={guest.id} guest={guest} idx={idx} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p>Loading...</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
@ -29,7 +29,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
|
||||
<div className="max-w-4xl w-full h-full bg-[#f9f9f7] shadow-lg">
|
||||
<div
|
||||
className="max-w-4xl lg:m-6 m-3 lg:px-6 px-3 py-24 border-2 border-[#d3d3d1] rounded-xl text-[#958971] flex justify-center"
|
||||
className="max-w-4xl lg:m-6 m-3 lg:px-6 px-3 lg:py-24 py-2 border-2 border-[#d3d3d1] rounded-xl text-[#958971] flex justify-center"
|
||||
style={{ height: 'calc(100% - 3rem)' }}
|
||||
>
|
||||
{children}
|
||||
|
@ -6,8 +6,16 @@ import { AbstractApi } from '@/app/api/abstract-api';
|
||||
import { Website, WebsiteSerializer } from '@/app/lib/website';
|
||||
import { useState, useEffect } from 'react';
|
||||
import DOMPurify from "dompurify";
|
||||
import { useParams } from 'next/navigation';
|
||||
|
||||
export default function Page() {
|
||||
const params = useParams<{ slug: string }>()
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem('slug', params.slug);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const [websiteContent, setWebsiteContent] = useState<string>("");
|
||||
|
||||
|
@ -49,6 +49,7 @@ export class AbstractApi<T extends Entity> implements Api<T> {
|
||||
body: serializable.toJson(object),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'X-CSRF-TOKEN': getCsrfToken(),
|
||||
}
|
||||
}).then(callback)
|
||||
@ -61,6 +62,7 @@ export class AbstractApi<T extends Entity> implements Api<T> {
|
||||
body: serializable.toJson(object),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'X-CSRF-TOKEN': getCsrfToken(),
|
||||
}
|
||||
})
|
||||
|
@ -5,8 +5,9 @@
|
||||
import { AbstractApi } from "@/app/api/abstract-api";
|
||||
import { Guest } from "@/app/lib/guest";
|
||||
import { Invitation, InvitationSerializer } from "@/app/lib/invitation";
|
||||
import { getSlug } from "@/app/lib/utils";
|
||||
import { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
||||
import { TrashIcon } from "@heroicons/react/24/outline";
|
||||
import { LinkIcon, TrashIcon } from "@heroicons/react/24/outline";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
@ -24,6 +25,8 @@ function InvitationCard({ invitation, allGuests, onGuestAdded, onDestroy }: {
|
||||
const api = new AbstractApi<Invitation>();
|
||||
const serializer = new InvitationSerializer();
|
||||
|
||||
const iconClassName = "w-5 h-5 text-white absolute top-2 opacity-0 group-hover:opacity-100 cursor-pointer";
|
||||
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
return dropTargetForElements({
|
||||
@ -53,8 +56,14 @@ function InvitationCard({ invitation, allGuests, onGuestAdded, onDestroy }: {
|
||||
className="relative flex items-center justify-center w-full bg-green-800 border border-green-900 group"
|
||||
style={{ aspectRatio: "1.618 / 1" }}
|
||||
>
|
||||
<LinkIcon
|
||||
className={`${iconClassName} right-8`}
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(`https://${window.location.host}/${getSlug()}/site/invitation/${invitation.id}`);
|
||||
}}
|
||||
/>
|
||||
<TrashIcon
|
||||
className="w-5 h-5 text-white absolute top-2 right-2 opacity-0 group-hover:opacity-100 cursor-pointer"
|
||||
className={`${iconClassName} right-2`}
|
||||
onClick={() => {
|
||||
if (window.confirm("Are you sure you want to delete this invitation?")) {
|
||||
api.destroy(serializer, invitation, () => {
|
||||
@ -64,6 +73,7 @@ function InvitationCard({ invitation, allGuests, onGuestAdded, onDestroy }: {
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
{guests.length === 0 ? (
|
||||
<p className="text-center text-yellow-500 text-lg italic">
|
||||
(empty invitation)
|
||||
|
Loading…
x
Reference in New Issue
Block a user