Compare commits
No commits in common. "main" and "fix-localstorage-issue" have entirely different histories.
main
...
fix-locals
31
.github/workflows/build.yml
vendored
31
.github/workflows/build.yml
vendored
@ -1,6 +1,8 @@
|
|||||||
name: Build Nginx-based docker image
|
name: Build Nginx-based docker image
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.ref }}
|
group: ${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
@ -23,31 +25,12 @@ jobs:
|
|||||||
username: ${{ secrets.PRIVATE_REGISTRY_USERNAME }}
|
username: ${{ secrets.PRIVATE_REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
password: ${{ secrets.PRIVATE_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push intermediate stages (deps)
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
target: deps
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
push: ${{ github.ref == 'refs/heads/main' }}
|
tags: |
|
||||||
tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:deps
|
${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest
|
||||||
cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:deps
|
cache-from: type=registry,ref=user/app:latest
|
||||||
cache-to: type=inline
|
|
||||||
|
|
||||||
- name: Build and push intermediate stages (builder)
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
target: builder
|
|
||||||
push: ${{ github.ref == 'refs/heads/main' }}
|
|
||||||
tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:builder
|
|
||||||
cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:builder
|
|
||||||
cache-to: type=inline
|
|
||||||
|
|
||||||
- name: Build and push (final)
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: ${{ github.ref == 'refs/heads/main' }}
|
|
||||||
tags: ${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest
|
|
||||||
cache-from: type=registry,ref=${{ secrets.PRIVATE_REGISTRY_HOST }}/${{ env.GITHUB_REPOSITORY }}:latest
|
|
||||||
cache-to: type=inline
|
cache-to: type=inline
|
2
.github/workflows/copyright_notice.yml
vendored
2
.github/workflows/copyright_notice.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
|||||||
ref: ${{ github.head_ref }}
|
ref: ${{ github.head_ref }}
|
||||||
- uses: VinnyBabuManjaly/copyright-action@v1.0.0
|
- uses: VinnyBabuManjaly/copyright-action@v1.0.0
|
||||||
with:
|
with:
|
||||||
CopyrightString: '/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/\n\n'
|
CopyrightString: '/* Copyright (C) 2024 Manuel Bustillo*/\n\n'
|
||||||
FileType: '.tsx, .jsx, .ts'
|
FileType: '.tsx, .jsx, .ts'
|
||||||
Path: 'app/, config/, db/'
|
Path: 'app/, config/, db/'
|
||||||
IgnorePath: 'testfolder1/a/, testfolder3'
|
IgnorePath: 'testfolder1/a/, testfolder3'
|
||||||
|
@ -1,44 +1,15 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client'
|
import { lusitana } from '@/app/ui/fonts';
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
|
||||||
import { Expense, ExpenseSerializer } from '@/app/lib/expense';
|
|
||||||
import { classNames } from '@/app/ui/components/button';
|
|
||||||
import ExpenseFormDialog from '@/app/ui/components/expense-form-dialog';
|
|
||||||
import ExpensesTable from '@/app/ui/expenses/table';
|
import ExpensesTable from '@/app/ui/expenses/table';
|
||||||
import SkeletonTable from '@/app/ui/guests/skeleton-row';
|
|
||||||
import { Suspense, useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
export default function Page() {
|
|
||||||
const refreshExpenses = () => {
|
|
||||||
new AbstractApi<Expense>().getAll(new ExpenseSerializer(), (expenses: Expense[]) => {
|
|
||||||
setExpenses(expenses);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const [expenses, setExpenses] = useState<Expense[]>([]);
|
|
||||||
const [expenseBeingEdited, setExpenseBeingEdited] = useState<Expense | undefined>(undefined);
|
|
||||||
useEffect(() => { refreshExpenses() }, []);
|
|
||||||
|
|
||||||
|
export default function Page () {
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex flex-col w-full items-center justify-between">
|
<div className="w-full items-center justify-between">
|
||||||
<button onClick={() => setExpenseBeingEdited({})} className={classNames('primary')}>Add new</button>
|
<h1 className={`${lusitana.className} text-2xl`}>Expenses</h1>
|
||||||
<ExpenseFormDialog
|
<h2 className={`${lusitana.className} text-xl`}>Summary</h2>
|
||||||
key={expenseBeingEdited?.id}
|
<ExpensesTable />
|
||||||
onCreate={() => { refreshExpenses(); setExpenseBeingEdited(undefined) }}
|
|
||||||
expense={expenseBeingEdited}
|
|
||||||
visible={expenseBeingEdited !== undefined}
|
|
||||||
onHide={() => { setExpenseBeingEdited(undefined) }}
|
|
||||||
/>
|
|
||||||
<Suspense fallback={<SkeletonTable />}>
|
|
||||||
<ExpensesTable
|
|
||||||
expenses={expenses}
|
|
||||||
onUpdate={refreshExpenses}
|
|
||||||
onEdit={(expense) => setExpenseBeingEdited(expense)}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { AbstractApi, } from '@/app/api/abstract-api';
|
import { loadGroups } from '@/app/api/groups';
|
||||||
import { Group, GroupSerializer } from '@/app/lib/group';
|
import { loadGuests } from '@/app/api/guests';
|
||||||
import { Guest, GuestSerializer } from '@/app/lib/guest';
|
import { Group, Guest } from '@/app/lib/definitions';
|
||||||
import { getCsrfToken, getSlug } from '@/app/lib/utils';
|
|
||||||
import AffinitiesFormDialog from '@/app/ui/components/affinities-form-dialog';
|
|
||||||
import { classNames } from '@/app/ui/components/button';
|
import { classNames } from '@/app/ui/components/button';
|
||||||
import GroupFormDialog from '@/app/ui/components/group-form-dialog';
|
|
||||||
import GuestFormDialog from '@/app/ui/components/guest-form-dialog';
|
import GuestFormDialog from '@/app/ui/components/guest-form-dialog';
|
||||||
import GroupsTable from '@/app/ui/groups/table';
|
import GroupsTable from '@/app/ui/groups/table';
|
||||||
import SkeletonTable from '@/app/ui/guests/skeleton-row';
|
import SkeletonTable from '@/app/ui/guests/skeleton-row';
|
||||||
@ -19,34 +16,21 @@ import { Suspense, useState } from 'react';
|
|||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
function refreshGuests() {
|
function refreshGuests() {
|
||||||
new AbstractApi<Guest>().getAll(new GuestSerializer(), (objects: Guest[]) => {
|
loadGuests((guests) => {
|
||||||
setGuests(objects);
|
setGuests(guests);
|
||||||
setGuestsLoaded(true);
|
setGuestsLoaded(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshGroups() {
|
function refreshGroups() {
|
||||||
new AbstractApi<Group>().getAll(new GroupSerializer(), (objects: Group[]) => {
|
loadGroups((groups) => {
|
||||||
setGroups(objects);
|
setGroups(groups);
|
||||||
setGroupsLoaded(true);
|
setGroupsLoaded(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetAffinities() {
|
|
||||||
fetch(`/api/${getSlug()}/groups/affinities/reset`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'X-CSRF-TOKEN': getCsrfToken(),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const [groupsLoaded, setGroupsLoaded] = useState(false);
|
const [groupsLoaded, setGroupsLoaded] = useState(false);
|
||||||
const [groups, setGroups] = useState<Array<Group>>([]);
|
const [groups, setGroups] = useState<Array<Group>>([]);
|
||||||
const [groupBeingEdited, setGroupBeingEdited] = useState<Group | undefined>(undefined);
|
|
||||||
|
|
||||||
const [groupAffinitiesBeingEditted, setGroupAffinitiesBeingEditted] = useState<Group | undefined>(undefined);
|
|
||||||
|
|
||||||
const [guestsLoaded, setGuestsLoaded] = useState(false);
|
const [guestsLoaded, setGuestsLoaded] = useState(false);
|
||||||
const [guests, setGuests] = useState<Array<Guest>>([]);
|
const [guests, setGuests] = useState<Array<Guest>>([]);
|
||||||
@ -70,45 +54,14 @@ export default function Page() {
|
|||||||
onHide={() => { setGuestBeingEdited(undefined) }}
|
onHide={() => { setGuestBeingEdited(undefined) }}
|
||||||
/>
|
/>
|
||||||
<Suspense fallback={<SkeletonTable />}>
|
<Suspense fallback={<SkeletonTable />}>
|
||||||
<GuestsTable
|
<GuestsTable guests={guests} onUpdate={refreshGuests} onEdit={(guest) => setGuestBeingEdited(guest)} />
|
||||||
guests={guests}
|
|
||||||
onUpdate={refreshGuests}
|
|
||||||
onEdit={(guest) => setGuestBeingEdited(guest)}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
</ TabPanel>
|
</ TabPanel>
|
||||||
<TabPanel header="Groups" leftIcon="pi pi-sitemap mx-2">
|
<TabPanel header="Groups" leftIcon="pi pi-sitemap mx-2">
|
||||||
<div className="flex flex-col w-full items-center justify-between">
|
<div className="flex w-full items-center justify-between">
|
||||||
|
|
||||||
<div>
|
|
||||||
<button onClick={() => setGroupBeingEdited({})} className={classNames('primary')}>Add new</button>
|
|
||||||
<button onClick={resetAffinities} className={classNames('yellow')}>Reset affinities</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<GroupFormDialog
|
|
||||||
key={groupBeingEdited?.id}
|
|
||||||
groups={groups}
|
|
||||||
onCreate={() => { refreshGroups(); setGroupBeingEdited(undefined) }}
|
|
||||||
group={groupBeingEdited}
|
|
||||||
visible={groupBeingEdited !== undefined}
|
|
||||||
onHide={() => { setGroupBeingEdited(undefined) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<AffinitiesFormDialog
|
|
||||||
groups={groups}
|
|
||||||
group={groupAffinitiesBeingEditted}
|
|
||||||
visible={groupAffinitiesBeingEditted !== undefined}
|
|
||||||
onHide={() => { setGroupAffinitiesBeingEditted(undefined) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Suspense fallback={<SkeletonTable />}>
|
<Suspense fallback={<SkeletonTable />}>
|
||||||
<GroupsTable
|
<GroupsTable groups={groups} />
|
||||||
groups={groups}
|
|
||||||
onUpdate={refreshGroups}
|
|
||||||
onEdit={(group) => setGroupBeingEdited(group)}
|
|
||||||
onEditAffinities={(group) => setGroupAffinitiesBeingEditted(group)}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
</ TabPanel>
|
</ TabPanel>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import SideNav from '@/app/ui/dashboard/sidenav';
|
import SideNav from '@/app/ui/dashboard/sidenav';
|
||||||
|
|
||||||
|
@ -1,26 +1,9 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client'
|
|
||||||
|
|
||||||
import { GlobalSummary as Summary } from '@/app/lib/definitions';
|
|
||||||
import { getSlug } from '@/app/lib/utils';
|
|
||||||
import GlobalSummary from '@/app/ui/dashboard/global-summary';
|
import GlobalSummary from '@/app/ui/dashboard/global-summary';
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const [globalSummary, setGlobalSummary] = useState<Summary | undefined>(undefined);
|
return(
|
||||||
|
<GlobalSummary />
|
||||||
function refreshSummary() {
|
|
||||||
fetch(`/api/${getSlug()}/summary`)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
setGlobalSummary(data);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(refreshSummary, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
globalSummary && <GlobalSummary summary={globalSummary} />
|
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -1,42 +1,16 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
|
||||||
import { TableSimulation, TableSimulationSerializer } from '@/app/lib/tableSimulation';
|
|
||||||
import Arrangement from '@/app/ui/arrangements/arrangement';
|
import Arrangement from '@/app/ui/arrangements/arrangement';
|
||||||
|
import React, { useState } from 'react';
|
||||||
import ArrangementsTable from '@/app/ui/arrangements/arrangements-table';
|
import ArrangementsTable from '@/app/ui/arrangements/arrangements-table';
|
||||||
import { classNames } from '@/app/ui/components/button';
|
|
||||||
import { Toast } from 'primereact/toast';
|
|
||||||
import React, { useRef, useState } from 'react';
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const toast = useRef<Toast>(null);
|
|
||||||
|
|
||||||
const show = () => {
|
|
||||||
toast.current?.show({
|
|
||||||
severity: 'success',
|
|
||||||
summary: 'Simulation created',
|
|
||||||
detail: 'Table distributions will be calculated shortly, please come back in some minutes'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const [currentArrangement, setCurrentArrangement] = useState<string | null>(null);
|
const [currentArrangement, setCurrentArrangement] = useState<string | null>(null);
|
||||||
|
|
||||||
function createSimulation() {
|
|
||||||
const api = new AbstractApi<TableSimulation>();
|
|
||||||
const serializer = new TableSimulationSerializer();
|
|
||||||
api.create(serializer, new TableSimulation(), show);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<div className="flex flex-col w-full items-center justify-between">
|
|
||||||
<Toast ref={toast} />
|
|
||||||
<button onClick={createSimulation} className={classNames('primary')}>Add new</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ArrangementsTable onArrangementSelected={setCurrentArrangement} />
|
<ArrangementsTable onArrangementSelected={setCurrentArrangement} />
|
||||||
{currentArrangement && <Arrangement key={currentArrangement} id={currentArrangement} />}
|
{currentArrangement && <Arrangement key={currentArrangement} id={currentArrangement} />}
|
||||||
</>
|
</>
|
||||||
|
@ -1,26 +1,14 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import LoginForm from '@/app/ui/components/login-form';
|
import LoginForm from '@/app/ui/components/login-form';
|
||||||
import RegistrationForm from '@/app/ui/components/registration-form';
|
import RegistrationForm from '@/app/ui/components/registration-form';
|
||||||
import { useParams } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import { useEffect } from 'react';
|
|
||||||
import { retrieveCSRFToken } from '../api/authentication';
|
|
||||||
import { getCsrfToken } from '../lib/utils';
|
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const params = useParams<{ slug: string }>()
|
const params = useParams<{ slug: string }>()
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (getCsrfToken() == 'unknown') {
|
|
||||||
retrieveCSRFToken();
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
localStorage.setItem('slug', await params.slug);
|
localStorage.setItem('slug', await params.slug);
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="flex min-h-screen flex-col p-6">
|
<main className="flex min-h-screen flex-col p-6">
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
import { Entity } from '@/app/lib/definitions';
|
|
||||||
import { getCsrfToken, getSlug } from '@/app/lib/utils';
|
|
||||||
|
|
||||||
export interface Api<T extends Entity> {
|
|
||||||
getAll(serializable: Serializable<T> ,callback: (objets: T[]) => void): void;
|
|
||||||
get(serializable: Serializable<T>, id: string, callback: (object: T) => void): void;
|
|
||||||
create(serializable: Serializable<T>, object: T, callback: () => void): void;
|
|
||||||
update(serializable: Serializable<T>, object: T, callback: () => void): void;
|
|
||||||
destroy(serializable: Serializable<T>, object: T, callback: () => void): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Serializable<T> {
|
|
||||||
fromJson(json: any): T;
|
|
||||||
toJson(object: T): string;
|
|
||||||
apiPath(): string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AbstractApi<T extends Entity> implements Api<T> {
|
|
||||||
getAll(serializable: Serializable<T>, callback: (objets: T[]) => void): void {
|
|
||||||
fetch(`/api/${getSlug()}/${serializable.apiPath()}`)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
callback(data.map((record: any) => {
|
|
||||||
return serializable.fromJson(record);
|
|
||||||
}));
|
|
||||||
}, (error) => {
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get(serializable: Serializable<T>, id: string, callback: (object: T) => void): void {
|
|
||||||
fetch(`/api/${getSlug()}/${serializable.apiPath()}/${id}`)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
callback(serializable.fromJson(data));
|
|
||||||
}, (error) => {
|
|
||||||
return [];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
update(serializable: Serializable<T>, object: T, callback: () => void): void {
|
|
||||||
fetch(`/api/${getSlug()}/${serializable.apiPath()}/${object.id}`, {
|
|
||||||
method: 'PUT',
|
|
||||||
body: serializable.toJson(object),
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-CSRF-TOKEN': getCsrfToken(),
|
|
||||||
}
|
|
||||||
}).then(callback)
|
|
||||||
.catch((error) => console.error(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
create(serializable: Serializable<T>, object: T, callback: () => void): void {
|
|
||||||
fetch(`/api/${getSlug()}/${serializable.apiPath()}`, {
|
|
||||||
method: 'POST',
|
|
||||||
body: serializable.toJson(object),
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-CSRF-TOKEN': getCsrfToken(),
|
|
||||||
}
|
|
||||||
}).then(callback)
|
|
||||||
.catch((error) => console.error(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
destroy(serializable: Serializable<T>, object: T, callback: () => void): void {
|
|
||||||
fetch(`/api/${getSlug()}/${serializable.apiPath()}/${object.id}`, {
|
|
||||||
method: 'DELETE',
|
|
||||||
headers: {
|
|
||||||
'X-CSRF-TOKEN': getCsrfToken(),
|
|
||||||
}
|
|
||||||
}).then(callback)
|
|
||||||
.catch((error) => console.error(error));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import { asArray, getCsrfToken, getSlug } from '@/app/lib/utils';
|
import { asArray, getCsrfToken, getSlug } from '@/app/lib/utils';
|
||||||
import { Captcha, StructuredErrors, User } from '@/app/lib/definitions';
|
import { Captcha, StructuredErrors, User } from '@/app/lib/definitions';
|
||||||
@ -35,7 +35,7 @@ export function logout({ onLogout }: { onLogout: () => void }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function flattenErrors(errors: StructuredErrors): string[] {
|
function flattenErrors(errors: StructuredErrors): string[] {
|
||||||
if (errors instanceof Array) {
|
if(errors instanceof Array) {
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
return Object.keys(errors).map((key) => {
|
return Object.keys(errors).map((key) => {
|
||||||
@ -43,16 +43,7 @@ function flattenErrors(errors: StructuredErrors): string[] {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this moment we're making an initial request to get a valid CSRF token
|
export function register({slug, email, password, passwordConfirmation, captcha, onRegister, onError}: {
|
||||||
export function retrieveCSRFToken() {
|
|
||||||
return fetch(`/api/token`, {
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
}
|
|
||||||
}).then((response) => { return null });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function register({ slug, email, password, passwordConfirmation, captcha, onRegister, onError }: {
|
|
||||||
slug: string,
|
slug: string,
|
||||||
email: string,
|
email: string,
|
||||||
password: string,
|
password: string,
|
||||||
@ -60,7 +51,7 @@ export function register({ slug, email, password, passwordConfirmation, captcha,
|
|||||||
captcha: Captcha,
|
captcha: Captcha,
|
||||||
onRegister: () => void,
|
onRegister: () => void,
|
||||||
onError: (errors: string[]) => void
|
onError: (errors: string[]) => void
|
||||||
}) {
|
}){
|
||||||
fetch(`/api/${slug}/users`, {
|
fetch(`/api/${slug}/users`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(
|
body: JSON.stringify(
|
||||||
@ -75,7 +66,7 @@ export function register({ slug, email, password, passwordConfirmation, captcha,
|
|||||||
'X-CSRF-TOKEN': getCsrfToken(),
|
'X-CSRF-TOKEN': getCsrfToken(),
|
||||||
}
|
}
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
if (response.ok) {
|
if(response.ok) {
|
||||||
response.json().then(onRegister);
|
response.json().then(onRegister);
|
||||||
} else {
|
} else {
|
||||||
response.json().then((data: any) => {
|
response.json().then((data: any) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import { data } from "autoprefixer";
|
import { data } from "autoprefixer";
|
||||||
import { getCsrfToken } from "../lib/utils";
|
import { getCsrfToken } from "../lib/utils";
|
||||||
|
40
app/api/expenses.tsx
Normal file
40
app/api/expenses.tsx
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
|
import { Expense } from '@/app/lib/definitions';
|
||||||
|
import { getCsrfToken, getSlug } from '@/app/lib/utils';
|
||||||
|
|
||||||
|
export function loadExpenses(onLoad?: (expenses: Expense[]) => void) {
|
||||||
|
fetch(`/api/${getSlug()}/expenses`)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
onLoad && onLoad(data.map((record: any) => {
|
||||||
|
return ({
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
amount: record.amount,
|
||||||
|
pricingType: record.pricing_type
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}, (error) => {
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateExpense(expense: Expense) {
|
||||||
|
fetch(`/api/${getSlug()}/expenses/${expense.id}`,
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({
|
||||||
|
expense: {
|
||||||
|
name: expense.name,
|
||||||
|
amount: expense.amount,
|
||||||
|
pricing_type: expense.pricingType,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-TOKEN': getCsrfToken(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => console.error(error));
|
||||||
|
}
|
28
app/api/groups.tsx
Normal file
28
app/api/groups.tsx
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
|
import { Group } from '@/app/lib/definitions';
|
||||||
|
import { getSlug } from '../lib/utils';
|
||||||
|
|
||||||
|
export function loadGroups(onLoad?: (groups: Group[]) => void) {
|
||||||
|
fetch(`/api/${getSlug()}/groups`)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
onLoad && onLoad(data.map((record: any) => {
|
||||||
|
return ({
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
color: record.color,
|
||||||
|
attendance: {
|
||||||
|
considered: record.considered,
|
||||||
|
invited: record.invited,
|
||||||
|
confirmed: record.confirmed,
|
||||||
|
tentative: record.tentative,
|
||||||
|
declined: record.declined,
|
||||||
|
total: record.total,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}, (error) => {
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
}
|
65
app/api/guests.tsx
Normal file
65
app/api/guests.tsx
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
|
import { Guest } from '@/app/lib/definitions';
|
||||||
|
import { getCsrfToken, getSlug } from '@/app/lib/utils';
|
||||||
|
|
||||||
|
export function loadGuests(onLoad?: (guests: Guest[]) => void) {
|
||||||
|
fetch(`/api/${getSlug()}/guests`)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
onLoad && onLoad(data.map((record: any) => {
|
||||||
|
return ({
|
||||||
|
id: record.id,
|
||||||
|
name: record.name,
|
||||||
|
status: record.status,
|
||||||
|
group_name: record.group.name,
|
||||||
|
groupId: record.group.id,
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}, (error) => {
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export function updateGuest(guest: Guest) {
|
||||||
|
return fetch(`/api/${getSlug()}/guests/${guest.id}`,
|
||||||
|
{
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ guest: { name: guest.name, status: guest.status, group_id: guest.groupId } }),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-TOKEN': getCsrfToken(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => console.error(error));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createGuest(guest: Guest, onCreate?: () => void) {
|
||||||
|
fetch(`/api/${getSlug()}/guests`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ name: guest.name, group_id: guest.groupId, status: guest.status }),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRF-TOKEN': getCsrfToken(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
onCreate && onCreate();
|
||||||
|
})
|
||||||
|
.catch((error) => console.error(error));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function destroyGuest(guest: Guest, onDestroy?: () => void) {
|
||||||
|
fetch(`/api/${getSlug()}/guests/${guest.id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': getCsrfToken(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
onDestroy && onDestroy();
|
||||||
|
})
|
||||||
|
.catch((error) => console.error(error));
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
import { NextResponse } from "next/server";
|
|
||||||
|
|
||||||
export function GET() {
|
|
||||||
return NextResponse.json({});
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import { TableArrangement } from '@/app/lib/definitions';
|
import { TableArrangement } from '@/app/lib/definitions';
|
||||||
import { getSlug } from '../lib/utils';
|
import { getSlug } from '../lib/utils';
|
||||||
@ -12,7 +12,6 @@ export function loadTableSimulations(onLoad?: (tableSimulations: TableArrangemen
|
|||||||
id: record.id,
|
id: record.id,
|
||||||
name: record.name,
|
name: record.name,
|
||||||
discomfort: record.discomfort,
|
discomfort: record.discomfort,
|
||||||
valid: record.valid,
|
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import '@/app/ui/global.css'
|
import '@/app/ui/global.css'
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
export class Affinities {
|
|
||||||
[key:string]: number;
|
|
||||||
}
|
|
@ -1,21 +1,66 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import { AttendanceSummary } from "./group";
|
// This file contains type definitions for your data.
|
||||||
import { Guest } from "./guest";
|
// It describes the shape of the data, and what data type each property should accept.
|
||||||
|
// For simplicity of teaching, we're manually defining these types.
|
||||||
|
// However, these types are generated automatically if you're using an ORM such as Prisma.
|
||||||
|
|
||||||
export interface Entity {
|
export const guestStatuses = ['considered', 'invited', 'confirmed', 'declined', 'tentative'] as const;
|
||||||
|
export type GuestStatus = typeof guestStatuses[number];
|
||||||
|
export type Guest = {
|
||||||
id?: string;
|
id?: string;
|
||||||
|
name?: string;
|
||||||
|
group_name?: string;
|
||||||
|
groupId?: string;
|
||||||
|
color?: string;
|
||||||
|
status?: GuestStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Expense = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
amount: number;
|
||||||
|
pricingType: 'fixed' | 'per person';
|
||||||
|
};
|
||||||
|
|
||||||
export type TableArrangement = {
|
export type TableArrangement = {
|
||||||
id: string;
|
id: string;
|
||||||
number: number;
|
number: number;
|
||||||
name: string;
|
name: string;
|
||||||
guests?: Guest[];
|
guests?: Guest[];
|
||||||
discomfort?: number;
|
discomfort?: number
|
||||||
valid?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type Group = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
guest_count: number;
|
||||||
|
icon: string;
|
||||||
|
children: Group[];
|
||||||
|
color?: string;
|
||||||
|
attendance?: AttendanceSummary
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AttendanceSummary = {
|
||||||
|
considered: number;
|
||||||
|
invited: number;
|
||||||
|
confirmed: number;
|
||||||
|
declined: number;
|
||||||
|
tentative: number;
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type guestsTable = {
|
||||||
|
id: string;
|
||||||
|
customer_id: string;
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
image_url: string;
|
||||||
|
date: string;
|
||||||
|
amount: number;
|
||||||
|
status: 'pending' | 'paid';
|
||||||
|
};
|
||||||
|
|
||||||
export type User = {
|
export type User = {
|
||||||
id: string;
|
id: string;
|
||||||
email: string;
|
email: string;
|
||||||
@ -27,24 +72,5 @@ export type Captcha = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type StructuredErrors = {
|
export type StructuredErrors = {
|
||||||
[key: string]: string[] | string;
|
[key: string]: string[]|string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GlobalSummary = {
|
|
||||||
expenses: ExpenseSummary;
|
|
||||||
guests: AttendanceSummary
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ExpenseSummary = {
|
|
||||||
projected: ExpensePossibleSummary;
|
|
||||||
confirmed: ExpensePossibleSummary;
|
|
||||||
status: StatusSummary;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ExpensePossibleSummary = {
|
|
||||||
total: number;
|
|
||||||
guests: number;
|
|
||||||
}
|
|
||||||
export type StatusSummary = {
|
|
||||||
paid: number;
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
import { Serializable } from "../api/abstract-api";
|
|
||||||
import { Entity } from "./definitions";
|
|
||||||
|
|
||||||
export const pricingTypes = ['fixed', 'per_person'] as const;
|
|
||||||
export type PricingType = typeof pricingTypes[number];
|
|
||||||
|
|
||||||
export class Expense implements Entity {
|
|
||||||
id?: string;
|
|
||||||
name?: string;
|
|
||||||
amount?: number;
|
|
||||||
pricingType?: PricingType;
|
|
||||||
|
|
||||||
constructor(id?: string, name?: string, amount?: number, pricingType?: PricingType) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name || '';
|
|
||||||
this.amount = amount || 0;
|
|
||||||
this.pricingType = pricingType || 'fixed';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ExpenseSerializer implements Serializable<Expense>{
|
|
||||||
fromJson(data: any): Expense {
|
|
||||||
return new Expense(data.id, data.name, data.amount, data.pricing_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(expense: Expense): string {
|
|
||||||
return JSON.stringify({
|
|
||||||
expense: {
|
|
||||||
name: expense.name,
|
|
||||||
amount: expense.amount,
|
|
||||||
pricing_type: expense.pricingType
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
apiPath(): string {
|
|
||||||
return 'expenses';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
import { Entity } from "./definitions";
|
|
||||||
|
|
||||||
export type AttendanceSummary = {
|
|
||||||
considered: number;
|
|
||||||
invited: number;
|
|
||||||
confirmed: number;
|
|
||||||
declined: number;
|
|
||||||
tentative: number;
|
|
||||||
total: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Group implements Entity {
|
|
||||||
id?: string;
|
|
||||||
name?: string;
|
|
||||||
guest_count?: number;
|
|
||||||
icon?: string;
|
|
||||||
children?: Group[];
|
|
||||||
parentId?: string;
|
|
||||||
color?: string;
|
|
||||||
attendance?: AttendanceSummary
|
|
||||||
|
|
||||||
constructor(id?: string, name?: string, guest_count?: number, icon?: string, children?: Group[], parentId?: string, color?: string, attendance?: AttendanceSummary) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.guest_count = guest_count;
|
|
||||||
this.icon = icon;
|
|
||||||
this.children = children;
|
|
||||||
this.parentId = parentId;
|
|
||||||
this.color = color;
|
|
||||||
this.attendance = attendance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class GroupSerializer {
|
|
||||||
fromJson(data: any): Group {
|
|
||||||
return new Group(
|
|
||||||
data.id,
|
|
||||||
data.name,
|
|
||||||
data.guest_count,
|
|
||||||
data.icon,
|
|
||||||
data.children,
|
|
||||||
data.parent_id,
|
|
||||||
data.color,
|
|
||||||
data.attendance
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(group: Group): string {
|
|
||||||
return JSON.stringify({
|
|
||||||
group: {
|
|
||||||
name: group.name,
|
|
||||||
color: group.color,
|
|
||||||
icon: group.icon,
|
|
||||||
parent_id: group.parentId
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
apiPath(): string {
|
|
||||||
return 'groups';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
import { Serializable } from "../api/abstract-api";
|
|
||||||
import { Entity } from "./definitions";
|
|
||||||
|
|
||||||
export const guestStatuses = ['considered', 'invited', 'confirmed', 'declined', 'tentative'] as const;
|
|
||||||
export type GuestStatus = typeof guestStatuses[number];
|
|
||||||
|
|
||||||
export class Guest implements Entity {
|
|
||||||
id?: string;
|
|
||||||
name?: string;
|
|
||||||
group_name?: string;
|
|
||||||
groupId?: string;
|
|
||||||
color?: string;
|
|
||||||
status?: GuestStatus;
|
|
||||||
children?: Guest[];
|
|
||||||
|
|
||||||
constructor(id?: string, name?: string, group_name?: string, groupId?: string, color?: string, status?: GuestStatus, children?: Guest[]) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.group_name = group_name;
|
|
||||||
this.groupId = groupId;
|
|
||||||
this.color = color;
|
|
||||||
this.status = status;
|
|
||||||
this.children = children;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class GuestSerializer implements Serializable<Guest> {
|
|
||||||
fromJson(data: any): Guest {
|
|
||||||
return new Guest(data.id, data.name, data.group?.name, data.group?.id, data.color, data.status, data.children);
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(guest: Guest): string {
|
|
||||||
return JSON.stringify({ guest: { name: guest.name, status: guest.status, group_id: guest.groupId } });
|
|
||||||
}
|
|
||||||
|
|
||||||
apiPath(): string {
|
|
||||||
return 'guests';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
import { Serializable } from "../api/abstract-api";
|
|
||||||
import { Entity } from "./definitions";
|
|
||||||
import { Guest } from "./guest";
|
|
||||||
|
|
||||||
export type Discomfort = {
|
|
||||||
discomfort: number;
|
|
||||||
breakdown: {
|
|
||||||
tableSizePenalty: number;
|
|
||||||
cohesionPenalty: number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Table = {
|
|
||||||
number: number;
|
|
||||||
guests: Guest[];
|
|
||||||
discomfort: Discomfort;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableSimulation implements Entity {
|
|
||||||
id?: string;
|
|
||||||
tables: Table[];
|
|
||||||
|
|
||||||
constructor(id?: string, tables?: Table[]) {
|
|
||||||
this.id = id;
|
|
||||||
this.tables = tables || [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableSimulationSerializer implements Serializable<TableSimulation> {
|
|
||||||
fromJson(data: any): TableSimulation {
|
|
||||||
return new TableSimulation(data.id, data.tables.map((table: any) => {
|
|
||||||
return {
|
|
||||||
number: table.number,
|
|
||||||
guests: table.guests.map((guest: any) => new Guest(guest.id, guest.name, guest.group?.name, guest.group?.id, guest.color)),
|
|
||||||
discomfort: {
|
|
||||||
discomfort: table.discomfort.discomfort,
|
|
||||||
breakdown: {
|
|
||||||
tableSizePenalty: table.discomfort.breakdown.table_size_penalty,
|
|
||||||
cohesionPenalty: table.discomfort.breakdown.cohesion_penalty,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(simulation: TableSimulation): string {
|
|
||||||
return JSON.stringify({ simulation: { tables: simulation.tables.map((table) => {
|
|
||||||
return {
|
|
||||||
number: table.number,
|
|
||||||
guests: table.guests.map((guest) => {
|
|
||||||
return {
|
|
||||||
id: guest.id,
|
|
||||||
name: guest.name,
|
|
||||||
group_id: guest.groupId,
|
|
||||||
color: guest.color,
|
|
||||||
status: guest.status,
|
|
||||||
children: guest.children,
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
discomfort: table.discomfort,
|
|
||||||
}
|
|
||||||
}) } });
|
|
||||||
}
|
|
||||||
|
|
||||||
apiPath(): string {
|
|
||||||
return 'tables_arrangements';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
export const getCsrfToken = () => {
|
export const getCsrfToken = () => {
|
||||||
return document.cookie
|
return document.cookie
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import * as HeroIcon from '@heroicons/react/24/outline'
|
import * as HeroIcon from '@heroicons/react/24/outline'
|
||||||
import { ComponentProps } from 'react'
|
import { ComponentProps } from 'react'
|
||||||
|
@ -1,34 +1,40 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
import React, { useState } from 'react';
|
||||||
import { TableArrangement } from '@/app/lib/definitions';
|
import { TableArrangement, Guest } from '@/app/lib/definitions';
|
||||||
import { TableSimulation, TableSimulationSerializer } from '@/app/lib/tableSimulation';
|
|
||||||
import { getSlug } from '@/app/lib/utils';
|
|
||||||
import { Table } from '@/app/ui/components/table';
|
|
||||||
import { lusitana } from '@/app/ui/fonts';
|
import { lusitana } from '@/app/ui/fonts';
|
||||||
import { useState, useEffect } from 'react';
|
import { Table } from '@/app/ui/components/table';
|
||||||
|
|
||||||
export default function Arrangement({ id }: { id: string }) {
|
export default function Arrangement({ id }: { id: string }) {
|
||||||
|
|
||||||
const [simulation, setSimulation] = useState<TableSimulation | undefined>(undefined);
|
const [tables, setTables] = useState<Array<TableArrangement>>([]);
|
||||||
|
|
||||||
function loadSimulation() {
|
function loadTables() {
|
||||||
new AbstractApi<TableSimulation>().get(new TableSimulationSerializer(), id, (object: TableSimulation) => {
|
fetch(`/api/tables_arrangements/${id}`)
|
||||||
setSimulation(object);
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
setTables(data.map((record: any) => {
|
||||||
|
return ({
|
||||||
|
id: record.number,
|
||||||
|
guests: record.guests
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}, (error) => {
|
||||||
|
return [];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(loadSimulation, []);
|
tables.length === 0 && loadTables();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="w-full items-center justify-between">
|
<div className="w-full items-center justify-between">
|
||||||
<h1 className={`${lusitana.className} text-2xl my-5`}>Table distributions</h1>
|
<h1 className={`${lusitana.className} text-2xl my-5`}>Table distributions</h1>
|
||||||
<div className="flex flex-row flex-wrap justify-around">
|
<div className="flex flex-row flex-wrap justify-around">
|
||||||
{simulation && simulation.tables.map((table) => (
|
{tables.map((table) => (
|
||||||
<Table key={table.number} table={table} style="rounded" />
|
<Table key={table.number} guests={table.guests || []} style="rounded" />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
@ -7,11 +7,8 @@ import { TableArrangement } from '@/app/lib/definitions';
|
|||||||
import { classNames } from "../components/button";
|
import { classNames } from "../components/button";
|
||||||
import TableOfContents from "../components/table-of-contents";
|
import TableOfContents from "../components/table-of-contents";
|
||||||
import { loadTableSimulations } from "@/app/api/tableSimulations";
|
import { loadTableSimulations } from "@/app/api/tableSimulations";
|
||||||
import { ArchiveBoxXMarkIcon, CheckBadgeIcon } from "@heroicons/react/24/outline";
|
|
||||||
import { Tooltip } from "primereact/tooltip";
|
|
||||||
import clsx from "clsx";
|
|
||||||
|
|
||||||
export default function ArrangementsTable({ onArrangementSelected }: { onArrangementSelected: (arrangementId: string) => void }) {
|
export default function ArrangementsTable ({onArrangementSelected}: {onArrangementSelected: (arrangementId: string) => void}) {
|
||||||
const [arrangements, setArrangements] = useState<Array<TableArrangement>>([]);
|
const [arrangements, setArrangements] = useState<Array<TableArrangement>>([]);
|
||||||
const [arrangementsLoaded, setArrangementsLoaded] = useState(false);
|
const [arrangementsLoaded, setArrangementsLoaded] = useState(false);
|
||||||
|
|
||||||
@ -28,17 +25,14 @@ export default function ArrangementsTable({ onArrangementSelected }: { onArrange
|
|||||||
|
|
||||||
!arrangementsLoaded && refreshSimulations();
|
!arrangementsLoaded && refreshSimulations();
|
||||||
|
|
||||||
return (
|
return(
|
||||||
<TableOfContents
|
<TableOfContents
|
||||||
headers={['Name', 'Discomfort', 'Actions', 'Status']}
|
headers={['Name', 'Discomfort', 'Actions']}
|
||||||
caption='Simulations'
|
caption='Simulations'
|
||||||
elements={arrangements}
|
elements={arrangements}
|
||||||
rowRender={(arrangement) => (
|
rowRender={(arrangement) => (
|
||||||
<tr key={arrangement.id} className={clsx("border-b", {
|
<tr key={arrangement.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
|
||||||
"bg-white odd:bg-white even:bg-gray-50": arrangement.valid,
|
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||||
"bg-red-50 odd:bg-red-50 even:bg-red-100": !arrangement.valid
|
|
||||||
})}>
|
|
||||||
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
|
||||||
{arrangement.name}
|
{arrangement.name}
|
||||||
</th>
|
</th>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4">
|
||||||
@ -47,15 +41,6 @@ export default function ArrangementsTable({ onArrangementSelected }: { onArrange
|
|||||||
<td>
|
<td>
|
||||||
<button data-arrangement-id={arrangement.id} onClick={arrangementClicked} className={classNames('primary')}>Load</button>
|
<button data-arrangement-id={arrangement.id} onClick={arrangementClicked} className={classNames('primary')}>Load</button>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<Tooltip target=".tooltip-status" />
|
|
||||||
|
|
||||||
{
|
|
||||||
arrangement.valid ?
|
|
||||||
<CheckBadgeIcon className='size-6 tooltip-status' data-pr-position="right" data-pr-tooltip="Simulation is valid" /> :
|
|
||||||
<ArchiveBoxXMarkIcon className='size-6 tooltip-status' data-pr-position="right" data-pr-tooltip="Simulation is expired due to attendance or affinity changes" />
|
|
||||||
}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
'use client';
|
|
||||||
|
|
||||||
import { Affinities } from '@/app/lib/affinities';
|
|
||||||
import { Group } from '@/app/lib/group';
|
|
||||||
import { getCsrfToken, getSlug } from '@/app/lib/utils';
|
|
||||||
import { classNames } from '@/app/ui/components/button';
|
|
||||||
import { Dialog } from 'primereact/dialog';
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
import AffinitySlider from './form/affinitySlider';
|
|
||||||
|
|
||||||
export default function AffinitiesFormDialog({ groups, group, visible, onHide }: {
|
|
||||||
groups: Group[],
|
|
||||||
group?: Group,
|
|
||||||
visible: boolean,
|
|
||||||
onHide: () => void,
|
|
||||||
}) {
|
|
||||||
const [affinities, setAffinities] = useState<Affinities>({});
|
|
||||||
const [isLoadingAffinities, setIsLoadingAffinities] = useState(true);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setIsLoadingAffinities(true);
|
|
||||||
if (group?.id === undefined) {
|
|
||||||
setAffinities({});
|
|
||||||
setIsLoadingAffinities(false)
|
|
||||||
} else {
|
|
||||||
fetch(`/api/${getSlug()}/groups/${group?.id}/affinities`)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
setAffinities(data);
|
|
||||||
setIsLoadingAffinities(false)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [group]);
|
|
||||||
|
|
||||||
function submitAffinities() {
|
|
||||||
const formattedAffinities = Object.entries(affinities).map(([groupId, affinity]) => ({ group_id: groupId, affinity: affinity }));
|
|
||||||
fetch(`/api/${getSlug()}/groups/${group?.id}/affinities/bulk_update`, {
|
|
||||||
method: 'PUT',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-CSRF-TOKEN': getCsrfToken(),
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ affinities: formattedAffinities })
|
|
||||||
}).then(() => {
|
|
||||||
onHide();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetAffinities() {
|
|
||||||
fetch(`/api/${getSlug()}/groups/${group?.id}/affinities/default`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
}
|
|
||||||
}).then((response) => response.json())
|
|
||||||
.then(setAffinities);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog header="Update affinities" visible={visible} style={{ width: '60vw' }} onHide={onHide}>
|
|
||||||
{!isLoadingAffinities && <div className="card justify-evenly py-5 bg-gray-200 flex flex-col">
|
|
||||||
<span className="text-center p-4">Describe the affinity with the rest of the groups</span>
|
|
||||||
|
|
||||||
{
|
|
||||||
groups.filter((currentGroup) => currentGroup.id !== group?.id).map((group) =>
|
|
||||||
<div key={group.id} className="flex flex-row hover:bg-gray-300 px-3 py-2 items-center">
|
|
||||||
<span className="w-1/3 text-right px-4">{group.name}</span>
|
|
||||||
<AffinitySlider value={group.id && affinities[group.id] || 1} onChange={(value) => setAffinities({ ...affinities, [group.id || "default"]: value })} />
|
|
||||||
</div>)
|
|
||||||
}
|
|
||||||
|
|
||||||
<div className="flex justify-center">
|
|
||||||
<button className={classNames('gray')} onClick={resetAffinities} >Reset</button>
|
|
||||||
<button className={classNames('primary')} onClick={submitAffinities} >Update</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,15 +1,14 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
type ButtonColor = 'primary' | 'blue' | 'green' | 'red' | 'yellow' | 'gray';
|
type ButtonColor = 'primary' | 'blue' | 'green' | 'red' | 'yellow';
|
||||||
|
|
||||||
export function classNames(type: ButtonColor) {
|
export function classNames(type: ButtonColor) {
|
||||||
return (clsx("text-white py-1 px-2 mx-1 rounded disabled:opacity-50 disabled:cursor-not-allowed", {
|
return (clsx("text-white py-1 px-2 mx-1 rounded disabled:opacity-50 disabled:cursor-not-allowed", {
|
||||||
'bg-blue-400 hover:bg-blue-600': type === 'primary' || type === 'blue',
|
'bg-blue-400 hover:bg-blue-600': type === 'primary' || type === 'blue',
|
||||||
'bg-green-500 hover:bg-green-600': type === 'green',
|
'bg-green-500 hover:bg-green-600': type === 'green',
|
||||||
'bg-red-500 hover:bg-red-600': type === 'red',
|
'bg-red-500 hover:bg-red-600': type === 'red',
|
||||||
'bg-yellow-500 hover:bg-yellow-700': type === 'yellow',
|
'bg-yellow-500 hover:bg-yellow-700': type === 'yellow'
|
||||||
'bg-gray-500 hover:bg-gray-700': type === 'gray'
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import clsx from "clsx"
|
import clsx from "clsx"
|
||||||
import { Icon } from "../../types";
|
import { Icon } from "../../types";
|
||||||
@ -21,7 +21,7 @@ const colorClasses = (style: Style) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MainCard({ amount, title, subtitle, style, iconName }:
|
export async function MainCard({ amount, title, subtitle, style, iconName }:
|
||||||
{
|
{
|
||||||
amount: string,
|
amount: string,
|
||||||
title: string,
|
title: string,
|
||||||
@ -42,7 +42,7 @@ export function MainCard({ amount, title, subtitle, style, iconName }:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SecondaryCard({ amount, title, iconName, style }: { amount: string, title: string, iconName: keyof typeof HeroIcon, style: Style }) {
|
export async function SecondaryCard({ amount, title, iconName, style }: { amount: string, title: string, iconName: keyof typeof HeroIcon, style: Style }) {
|
||||||
return (
|
return (
|
||||||
<div className={`h-12 w-80 m-1 p-2 text-white flex flex-row items-center ${colorClasses(style)}`}>
|
<div className={`h-12 w-80 m-1 p-2 text-white flex flex-row items-center ${colorClasses(style)}`}>
|
||||||
<Icon className="m-3 h-7 w-7" name={iconName} />
|
<Icon className="m-3 h-7 w-7" name={iconName} />
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
'use client';
|
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
|
||||||
import { Expense, ExpenseSerializer, PricingType, pricingTypes } from '@/app/lib/expense';
|
|
||||||
import { capitalize } from '@/app/lib/utils';
|
|
||||||
import { classNames } from '@/app/ui/components/button';
|
|
||||||
import { Dialog } from 'primereact/dialog';
|
|
||||||
import { Dropdown } from 'primereact/dropdown';
|
|
||||||
import { FloatLabel } from 'primereact/floatlabel';
|
|
||||||
import { InputText } from 'primereact/inputtext';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
export default function ExpenseFormDialog({ onCreate, onHide, expense, visible }: {
|
|
||||||
onCreate?: () => void,
|
|
||||||
onHide: () => void,
|
|
||||||
expense?: Expense,
|
|
||||||
visible: boolean,
|
|
||||||
}) {
|
|
||||||
|
|
||||||
const [name, setName] = useState<string>(expense?.name || '');
|
|
||||||
const [amount, setAmount] = useState<number>(expense?.amount || 0);
|
|
||||||
const [pricingType, setPricingType] = useState<PricingType>(expense?.pricingType || 'fixed');
|
|
||||||
|
|
||||||
const api = new AbstractApi<Expense>();
|
|
||||||
const serializer = new ExpenseSerializer();
|
|
||||||
|
|
||||||
function resetForm() {
|
|
||||||
setName('');
|
|
||||||
setAmount(0);
|
|
||||||
setPricingType('fixed');
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitGroup() {
|
|
||||||
if (expense?.id !== undefined) {
|
|
||||||
expense.name = name;
|
|
||||||
expense.amount = amount;
|
|
||||||
expense.pricingType = pricingType;
|
|
||||||
|
|
||||||
api.update(serializer, expense, () => {
|
|
||||||
resetForm();
|
|
||||||
onCreate && onCreate();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
|
|
||||||
api.create(serializer, new Expense(undefined, name, amount, pricingType), () => {
|
|
||||||
resetForm();
|
|
||||||
onCreate && onCreate();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
|
|
||||||
<Dialog header="Add/edit expense" visible={visible} style={{ width: '60vw' }} onHide={onHide}>
|
|
||||||
<div className="card flex justify-evenly py-5">
|
|
||||||
<FloatLabel>
|
|
||||||
<InputText id="name" className='rounded-sm' value={name} onChange={(e) => setName(e.target.value)} />
|
|
||||||
<label htmlFor="name">Name</label>
|
|
||||||
</FloatLabel>
|
|
||||||
<FloatLabel>
|
|
||||||
<InputText id="amount" className='rounded-sm' value={amount.toString()} onChange={(e) => setAmount(parseFloat(e.target.value))} />
|
|
||||||
<label htmlFor="amount">Amount</label>
|
|
||||||
</FloatLabel>
|
|
||||||
<FloatLabel>
|
|
||||||
<Dropdown id="pricingType" className='rounded-sm min-w-32' value={pricingType} onChange={(e) => setPricingType(e.target.value)} options={
|
|
||||||
pricingTypes.map((type) => {
|
|
||||||
return { label: capitalize(type), value: type };
|
|
||||||
})
|
|
||||||
} />
|
|
||||||
<label htmlFor="pricingType">Pricing type</label>
|
|
||||||
</FloatLabel>
|
|
||||||
|
|
||||||
<button className={classNames('primary')} onClick={submitGroup} disabled={!(name.length > 0)}>
|
|
||||||
{expense?.id !== undefined ? 'Update' : 'Create'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</Dialog>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
import { Slider } from 'primereact/slider';
|
|
||||||
|
|
||||||
export default function AffinitySlider({ value, onChange }: { value: number, onChange: (value: number) => void }) {
|
|
||||||
|
|
||||||
const toNumber = (value : number | [number, number]) => {
|
|
||||||
if(value instanceof Array) {
|
|
||||||
return value[0];
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const label = (value: number) => {
|
|
||||||
if (value < 0.2) {
|
|
||||||
return 'Nemesis';
|
|
||||||
} else if (value < 0.5) {
|
|
||||||
return 'Enemies';
|
|
||||||
} else if (value < 0.9) {
|
|
||||||
return 'Bad vibes';
|
|
||||||
} else if (value < 1.1) {
|
|
||||||
return 'Neutral';
|
|
||||||
} else if (value < 1.5) {
|
|
||||||
return 'Good vibes';
|
|
||||||
} else if (value < 1.8) {
|
|
||||||
return 'Good friends';
|
|
||||||
} else {
|
|
||||||
return 'Besties';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Slider value={value} min={0} max={2} step={.1} onChange={(e) => onChange(toNumber(e.value))} className='w-80 bg-gray-400' />
|
|
||||||
<span className="px-4 w-1/5">
|
|
||||||
{label(value)}
|
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
|
||||||
|
|
||||||
'use client';
|
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
|
||||||
import { Group, GroupSerializer } from '@/app/lib/group';
|
|
||||||
import { classNames } from '@/app/ui/components/button';
|
|
||||||
import { ColorPicker } from 'primereact/colorpicker';
|
|
||||||
import { Dialog } from 'primereact/dialog';
|
|
||||||
import { Dropdown } from 'primereact/dropdown';
|
|
||||||
import { FloatLabel } from 'primereact/floatlabel';
|
|
||||||
import { InputText } from 'primereact/inputtext';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
export default function GroupFormDialog({ groups, onCreate, onHide, group, visible }: {
|
|
||||||
groups: Group[],
|
|
||||||
onCreate?: () => void,
|
|
||||||
onHide: () => void,
|
|
||||||
group?: Group,
|
|
||||||
visible: boolean,
|
|
||||||
}) {
|
|
||||||
|
|
||||||
const [name, setName] = useState(group?.name || '');
|
|
||||||
const [icon, setIcon] = useState(group?.icon || '');
|
|
||||||
const [color, setColor] = useState<string>(group?.color || '');
|
|
||||||
const [parentId, setParentId] = useState(group?.parentId || '');
|
|
||||||
|
|
||||||
const api = new AbstractApi<Group>();
|
|
||||||
const serializer = new GroupSerializer();
|
|
||||||
|
|
||||||
function resetForm() {
|
|
||||||
setName('');
|
|
||||||
setIcon('');
|
|
||||||
setColor('');
|
|
||||||
setParentId('');
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitGroup() {
|
|
||||||
if (!(name)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (group?.id !== undefined) {
|
|
||||||
group.name = name;
|
|
||||||
group.icon = icon;
|
|
||||||
group.color = color;
|
|
||||||
group.parentId = parentId;
|
|
||||||
|
|
||||||
api.update(serializer, group, () => {
|
|
||||||
resetForm();
|
|
||||||
onCreate && onCreate();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
|
|
||||||
api.create(serializer, new Group(undefined, name, undefined, icon, undefined, parentId, color), () => {
|
|
||||||
resetForm();
|
|
||||||
onCreate && onCreate();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
|
|
||||||
<Dialog header="Add group" visible={visible} style={{ width: '60vw' }} onHide={onHide}>
|
|
||||||
<div className="card flex justify-evenly py-5">
|
|
||||||
<FloatLabel>
|
|
||||||
<InputText id="name" className='rounded-sm' value={name} onChange={(e) => setName(e.target.value)} />
|
|
||||||
<label htmlFor="name">Name</label>
|
|
||||||
</FloatLabel>
|
|
||||||
<FloatLabel>
|
|
||||||
<InputText id="icon" className='rounded-sm' value={icon} onChange={(e) => setIcon(e.target.value)} />
|
|
||||||
<label htmlFor="icon">Icon</label>
|
|
||||||
</FloatLabel>
|
|
||||||
<FloatLabel>
|
|
||||||
<ColorPicker value={color} format='hex' onChange={(e) => setColor(`#${e.value}`)} />
|
|
||||||
<label htmlFor="color" />
|
|
||||||
</FloatLabel>
|
|
||||||
<FloatLabel>
|
|
||||||
<Dropdown id="parentId" className='rounded-sm min-w-32' value={parentId} onChange={(e) => setParentId(e.target.value)} options={
|
|
||||||
groups.map((group) => {
|
|
||||||
return { label: group.name, value: group.id };
|
|
||||||
})
|
|
||||||
} />
|
|
||||||
<label htmlFor="parentId">Parent</label>
|
|
||||||
</FloatLabel>
|
|
||||||
|
|
||||||
<button className={classNames('primary')} onClick={submitGroup} disabled={!(name.length > 0)}>
|
|
||||||
{group?.id !== undefined ? 'Update' : 'Create'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</Dialog>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,10 +1,9 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
import { createGuest, updateGuest } from '@/app/api/guests';
|
||||||
import { Group } from '@/app/lib/group';
|
import { Group, Guest, GuestStatus, guestStatuses } from '@/app/lib/definitions';
|
||||||
import { Guest, GuestSerializer, GuestStatus, guestStatuses } from '@/app/lib/guest';
|
|
||||||
import { capitalize } from '@/app/lib/utils';
|
import { capitalize } from '@/app/lib/utils';
|
||||||
import { classNames } from '@/app/ui/components/button';
|
import { classNames } from '@/app/ui/components/button';
|
||||||
import { Dialog } from 'primereact/dialog';
|
import { Dialog } from 'primereact/dialog';
|
||||||
@ -25,9 +24,6 @@ export default function GuestFormDialog({ groups, onCreate, onHide, guest, visib
|
|||||||
const [group, setGroup] = useState(guest?.groupId || null);
|
const [group, setGroup] = useState(guest?.groupId || null);
|
||||||
const [status, setStatus] = useState<GuestStatus | null>(guest?.status || null);
|
const [status, setStatus] = useState<GuestStatus | null>(guest?.status || null);
|
||||||
|
|
||||||
const api = new AbstractApi<Guest>();
|
|
||||||
const serializer = new GuestSerializer();
|
|
||||||
|
|
||||||
function resetForm() {
|
function resetForm() {
|
||||||
setName('');
|
setName('');
|
||||||
setGroup(null);
|
setGroup(null);
|
||||||
@ -43,13 +39,12 @@ export default function GuestFormDialog({ groups, onCreate, onHide, guest, visib
|
|||||||
guest.name = name;
|
guest.name = name;
|
||||||
guest.groupId = group;
|
guest.groupId = group;
|
||||||
guest.status = status;
|
guest.status = status;
|
||||||
|
updateGuest(guest).then(() => {
|
||||||
api.update(serializer, guest, () => {
|
|
||||||
resetForm();
|
resetForm();
|
||||||
onCreate && onCreate();
|
onCreate && onCreate();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
api.create(serializer, new Guest(undefined, name, undefined, group, undefined, status), ()=> {
|
guest && createGuest({name: name, groupId: group, status: status}, () => {
|
||||||
resetForm();
|
resetForm();
|
||||||
onCreate && onCreate();
|
onCreate && onCreate();
|
||||||
});
|
});
|
||||||
@ -59,7 +54,7 @@ export default function GuestFormDialog({ groups, onCreate, onHide, guest, visib
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<Dialog header="Add guest" visible={visible} style={{ width: '60vw' }} onHide={onHide}>
|
<Dialog header="Add guest" visible={visible} style={{ width: '50vw' }} onHide={onHide}>
|
||||||
<div className="card flex justify-evenly py-5">
|
<div className="card flex justify-evenly py-5">
|
||||||
<FloatLabel>
|
<FloatLabel>
|
||||||
<InputText id="username" className='rounded-sm' value={name} onChange={(e) => setName(e.target.value)} />
|
<InputText id="username" className='rounded-sm' value={name} onChange={(e) => setName(e.target.value)} />
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
export default function TableOfContents<Type>({ headers, caption, elements, rowRender }: { headers: string[], caption: string, elements: Type[], rowRender: (element: Type) => JSX.Element }) {
|
export default function TableOfContents<Type>({ headers, caption, elements, rowRender }: { headers: string[], caption: string, elements: Type[], rowRender: (element: Type) => JSX.Element }) {
|
||||||
return (
|
return (
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import { Guest } from "@/app/lib/guest";
|
|
||||||
import { Table as TableType } from "@/app/lib/tableSimulation";
|
|
||||||
import { RectangleGroupIcon, UserGroupIcon } from "@heroicons/react/24/outline";
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
import { Tooltip } from "primereact/tooltip";
|
|
||||||
import clsx from "clsx";
|
|
||||||
|
|
||||||
|
import { Guest } from "@/app/lib/definitions";
|
||||||
|
|
||||||
function Dish({ guest, rotation }: { guest: Guest, rotation?: number }) {
|
function Dish({ guest, rotation }: { guest: Guest, rotation?: number }) {
|
||||||
rotation = rotation || 0
|
rotation = rotation || 0
|
||||||
@ -20,6 +14,7 @@ function Dish({ guest, rotation }: { guest: Guest, rotation?: number }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function GuestRow({ guests }: { guests: Guest[] }) {
|
function GuestRow({ guests }: { guests: Guest[] }) {
|
||||||
return (
|
return (
|
||||||
<div className="justify-around flex flex-row">
|
<div className="justify-around flex flex-row">
|
||||||
@ -28,8 +23,7 @@ function GuestRow({ guests }: { guests: Guest[] }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function RectangularTable({ table }: { table: TableType }) {
|
function RectangularTable({ guests }: { guests: Guest[] }) {
|
||||||
const guests = table.guests;
|
|
||||||
const halfwayThrough = Math.floor(guests.length / 2)
|
const halfwayThrough = Math.floor(guests.length / 2)
|
||||||
const arrayFirstHalf = guests.slice(0, halfwayThrough);
|
const arrayFirstHalf = guests.slice(0, halfwayThrough);
|
||||||
const arraySecondHalf = guests.slice(halfwayThrough, guests.length);
|
const arraySecondHalf = guests.slice(halfwayThrough, guests.length);
|
||||||
@ -42,24 +36,11 @@ function RectangularTable({ table }: { table: TableType }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function RoundedTable({ table }: { table: TableType }) {
|
function RoundedTable({ guests }: { guests: Guest[] }) {
|
||||||
const guests = table.guests;
|
|
||||||
const size = 500
|
const size = 500
|
||||||
const rotation = 360 / guests.length
|
const rotation = 360 / guests.length
|
||||||
|
|
||||||
const className = (penalty: number) => {
|
|
||||||
return clsx("px-2 tooltip-cohesion", {
|
|
||||||
"hidden": penalty === 0,
|
|
||||||
"text-orange-300": penalty <= 5,
|
|
||||||
"text-orange-500": penalty > 5 && penalty <= 10,
|
|
||||||
"text-orange-700": penalty > 10,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`m-12 rounded-full bg-cyan-800 relative z-0 grid flex items-center justify-items-center`} style={{ width: `${size}px`, height: `${size}px` }}>
|
<div className={`m-12 rounded-full bg-cyan-800 relative z-0`} style={{ width: `${size}px`, height: `${size}px` }}>
|
||||||
|
|
||||||
{
|
{
|
||||||
guests.map((guest, index) => {
|
guests.map((guest, index) => {
|
||||||
return (
|
return (
|
||||||
@ -73,35 +54,15 @@ function RoundedTable({ table }: { table: TableType }) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
<div className="bg-zinc-200 w-48 h-12 p-3 flex flex-row rounded z-10">
|
|
||||||
<div className="px-2 text-slate-800">{`Table #${table.number}`}</div>
|
|
||||||
|
|
||||||
|
|
||||||
<Tooltip target=".tooltip-cohesion" />
|
|
||||||
<Tooltip target=".tooltip-size" />
|
|
||||||
|
|
||||||
<RectangleGroupIcon
|
|
||||||
className={className(table.discomfort.breakdown.cohesionPenalty)}
|
|
||||||
data-pr-tooltip={`Cohesion penalty: ${Math.round(table.discomfort.breakdown.cohesionPenalty)}`}
|
|
||||||
data-pr-position="top"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<UserGroupIcon
|
|
||||||
className={className(table.discomfort.breakdown.tableSizePenalty)}
|
|
||||||
data-pr-tooltip={`Table size penalty: ${Math.round(table.discomfort.breakdown.tableSizePenalty)}`}
|
|
||||||
data-pr-position="top"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Table({ table, style }: { table: TableType, style: "rectangular" | "rounded" }) {
|
export function Table({ guests, style }: { guests: Guest[], style: "rectangular" | "rounded" }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{style === "rectangular" && <RectangularTable table={table} />}
|
{style === "rectangular" && <RectangularTable guests={guests} />}
|
||||||
{style === "rounded" && <RoundedTable table={table} />}
|
{style === "rounded" && <RoundedTable guests={guests} />}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -1,41 +1,45 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import { GlobalSummary as Summary} from '@/app/lib/definitions';
|
|
||||||
import { MainCard, SecondaryCard } from '../components/dashboard-cards';
|
import { MainCard, SecondaryCard } from '../components/dashboard-cards';
|
||||||
|
|
||||||
export default function GlobalSummary({ summary }: { summary: Summary }) {
|
export default async function GlobalSummary() {
|
||||||
return (
|
return (
|
||||||
<div className="my-4">
|
<div className="my-4">
|
||||||
<div className="flex flex-row w-full my-2">
|
|
||||||
<div className="flex flex-col">
|
|
||||||
<MainCard amount={`${summary.expenses.projected.total}€`} title="Projected" subtitle={`${summary.expenses.projected.guests} guests`} style="blue" iconName="ArrowTrendingUpIcon" />
|
|
||||||
<MainCard amount={`${Math.round(summary.expenses.projected.total / summary.expenses.projected.guests)}€`} title="/ guest" iconName="UserIcon" style='blue' />
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col">
|
|
||||||
<MainCard amount={`${summary.expenses.confirmed.total}€`} title="Min." subtitle={`${summary.expenses.confirmed.guests} guests`} iconName="ChevronDoubleDownIcon" style="green" />
|
|
||||||
<MainCard amount={`${Math.round(summary.expenses.confirmed.total / summary.expenses.confirmed.guests)}€`} title="/ guest" iconName="UserIcon" style='green' />
|
|
||||||
|
|
||||||
|
<div className="flex flex-row w-full my-2">
|
||||||
|
<MainCard style="green" amount="65000€" title="Projected" subtitle="150 guests" iconName="ArrowTrendingUpIcon" />
|
||||||
|
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<MainCard amount="10000€" title="Paid already" iconName="Square3Stack3DIcon" style='blue' />
|
||||||
|
<MainCard amount="198€" title="/ guest" iconName="UserIcon" style='blue' />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<MainCard amount={`${summary.expenses.status.paid}€`} title="Paid already" subtitle={`${Math.round(summary.expenses.status.paid / summary.expenses.projected.total * 100)}% of projected`} iconName="CheckIcon" style='blue' />
|
<MainCard amount="78000€" title="Max." subtitle='200 guests' iconName="ChevronDoubleUpIcon" style="orange" />
|
||||||
<MainCard amount={`${summary.expenses.projected.total - summary.expenses.status.paid}€`} title="To pay" subtitle={`${100 - Math.round(summary.expenses.status.paid / summary.expenses.projected.total * 100)}% of projected`} iconName="BanknotesIcon" style="orange" />
|
<MainCard amount="45000€" title="Min." subtitle="125 guests" iconName="ChevronDoubleDownIcon" style="green" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-row w-full my-2">
|
<div className="flex flex-row w-full my-2">
|
||||||
<MainCard style="blue" amount={summary.guests.total.toString()} title="Invites sent" iconName="UsersIcon" />
|
<MainCard style="blue" amount="150" title="Invites sent" iconName="UsersIcon" />
|
||||||
|
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<SecondaryCard amount={`${Math.round(summary.guests.confirmed / summary.guests.total * 100)}%`} title={`confirmed (${summary.guests.confirmed} guests)`} iconName="CheckIcon" style='green' />
|
<SecondaryCard amount="31%" title="confirmed (27 guests)" iconName="CheckIcon" style='green' />
|
||||||
<SecondaryCard amount={`${Math.round(summary.guests.declined / summary.guests.total * 100)}%`} title={`declined (${summary.guests.declined} guests)`} iconName="XMarkIcon" style='red' />
|
<SecondaryCard amount="5%" title="declined (8 guests)" iconName="XMarkIcon" style='red' />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<SecondaryCard amount={`${Math.round(summary.guests.tentative / summary.guests.total * 100)}%`} title={`tentative (${summary.guests.tentative} guests)`} iconName="QuestionMarkCircleIcon" style='orange' />
|
<SecondaryCard amount="17%" title="tentative (14 guests)" iconName="QuestionMarkCircleIcon" style='orange' />
|
||||||
<SecondaryCard amount={`${Math.round(summary.guests.invited / summary.guests.total * 100)}%`} title={`awaiting (${summary.guests.invited} guests)`} iconName="EllipsisHorizontalIcon" style='gray' />
|
<SecondaryCard amount="65%" title="awaiting (72 guests)" iconName="EllipsisHorizontalIcon" style='gray' />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-row w-full my-2">
|
||||||
|
<MainCard style="blue" amount="5" title="Table simulations" iconName="ServerStackIcon" />
|
||||||
|
<MainCard style="blue" amount="9" title="Bus simulations" iconName="TruckIcon" />
|
||||||
|
<MainCard style="blue" amount="98" title="QR codes" iconName="QrCodeIcon" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
export default function Loading() {
|
export default function Loading() {
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ export default function SideNav() {
|
|||||||
<div className="flex h-full flex-col px-3 py-4 md:px-2">
|
<div className="flex h-full flex-col px-3 py-4 md:px-2">
|
||||||
<Link
|
<Link
|
||||||
className="mb-2 flex h-20 items-center justify-start rounded-md bg-blue-600 p-4 md:h-20"
|
className="mb-2 flex h-20 items-center justify-start rounded-md bg-blue-600 p-4 md:h-20"
|
||||||
href={`/${getSlug()}/dashboard`}
|
href="/dashboard/guests"
|
||||||
>
|
>
|
||||||
<div className={`${gloriaHallelujah.className} "w-32 text-white md:w-40 antialiased`}>
|
<div className={`${gloriaHallelujah.className} "w-32 text-white md:w-40 antialiased`}>
|
||||||
<h1>Wedding Planner</h1>
|
<h1>Wedding Planner</h1>
|
||||||
|
@ -1,44 +1,42 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
import { loadExpenses, updateExpense } from '@/app/api/expenses';
|
||||||
import { Expense, ExpenseSerializer } from '@/app/lib/expense';
|
import { Expense } from '@/app/lib/definitions';
|
||||||
import { PencilIcon, TrashIcon } from '@heroicons/react/24/outline';
|
import { useState } from "react";
|
||||||
|
import InlineTextField from "../components/form/inlineTextField";
|
||||||
import TableOfContents from "../components/table-of-contents";
|
import TableOfContents from "../components/table-of-contents";
|
||||||
|
|
||||||
|
export default function ExpensesTable() {
|
||||||
|
const [expenses, setExpenses] = useState<Array<Expense>>([]);
|
||||||
|
const [expensesLoaded, setExpensesLoaded] = useState(false);
|
||||||
|
|
||||||
export default function ExpensesTable({ expenses, onUpdate, onEdit }: {
|
function refreshExpenses() {
|
||||||
expenses: Expense[],
|
loadExpenses((expenses) => {
|
||||||
onUpdate: () => void,
|
setExpenses(expenses);
|
||||||
onEdit: (expense: Expense) => void,
|
setExpensesLoaded(true);
|
||||||
}) {
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const api = new AbstractApi<Expense>();
|
!expensesLoaded && refreshExpenses();
|
||||||
const serializer = new ExpenseSerializer();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableOfContents
|
<TableOfContents
|
||||||
headers={['Name', 'Amount (€)', 'Pricing Type', 'Actions']}
|
headers={['Name', 'Amount (€)', 'Pricing Type']}
|
||||||
caption='Expenses'
|
caption='Expenses'
|
||||||
elements={expenses}
|
elements={expenses}
|
||||||
rowRender={(expense) => (
|
rowRender={(expense) => (
|
||||||
<tr key={expense.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
|
<tr key={expense.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
|
||||||
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||||
{expense.name}
|
<InlineTextField initialValue={expense.name} onChange={(value) => { expense.name = value; updateExpense(expense) }} />
|
||||||
</th>
|
</th>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4">
|
||||||
{expense.amount}
|
<InlineTextField initialValue={expense.amount.toString()} onChange={(value) => { expense.amount = parseFloat(value); updateExpense(expense) }} />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{expense.pricingType}
|
{expense.pricingType}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<div className="flex flex-row items-center">
|
|
||||||
<TrashIcon className='size-6 cursor-pointer' onClick={() => { api.destroy(serializer, expense, onUpdate) }} />
|
|
||||||
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(expense)} />
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import { Inter, Lusitana, Gloria_Hallelujah} from 'next/font/google';
|
import { Inter, Lusitana, Gloria_Hallelujah} from 'next/font/google';
|
||||||
|
|
||||||
|
@ -1,105 +1,45 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
import { Group } from '@/app/lib/definitions';
|
||||||
import { Group, GroupSerializer } from '@/app/lib/group';
|
import TableOfContents from '../components/table-of-contents';
|
||||||
import { AdjustmentsHorizontalIcon, PencilIcon, TrashIcon } from '@heroicons/react/24/outline';
|
|
||||||
import { Column } from 'primereact/column';
|
|
||||||
import { TreeNode } from 'primereact/treenode';
|
|
||||||
import { TreeTable } from 'primereact/treetable';
|
|
||||||
|
|
||||||
export default function GroupsTable({ groups, onUpdate, onEdit, onEditAffinities }: {
|
export default function GroupsTable({ groups }: { groups: Group[] }) {
|
||||||
groups: Group[],
|
|
||||||
onUpdate: () => void,
|
|
||||||
onEdit: (group: Group) => void,
|
|
||||||
onEditAffinities: (group: Group) => void,
|
|
||||||
}) {
|
|
||||||
|
|
||||||
const api = new AbstractApi<Group>();
|
|
||||||
const serializer = new GroupSerializer();
|
|
||||||
|
|
||||||
const actions = (group: Group) => (
|
|
||||||
<div className="flex flex-row items-center">
|
|
||||||
<TrashIcon className='size-6 cursor-pointer' onClick={() => { api.destroy(serializer, group, onUpdate) }} />
|
|
||||||
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(group)} />
|
|
||||||
<AdjustmentsHorizontalIcon className='size-6 cursor-pointer' onClick={() => onEditAffinities(group)} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
const index = groups.reduce((acc, group) => {
|
|
||||||
if (group.id) {
|
|
||||||
acc.set(group.id, group)
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
}, new Map());
|
|
||||||
|
|
||||||
groups.forEach(group => group.children = []);
|
|
||||||
groups.forEach(group => {
|
|
||||||
if (group.parentId) {
|
|
||||||
const parent = index.get(group.parentId);
|
|
||||||
if (parent) {
|
|
||||||
if (!parent.children) {
|
|
||||||
parent.children = [];
|
|
||||||
}
|
|
||||||
parent.children.push(group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const renderTree = (group: Group): TreeNode => {
|
|
||||||
const childrenAttendance = (group.children || []).reduce((acc, child) => {
|
|
||||||
acc.confirmed += child.attendance?.confirmed || 0;
|
|
||||||
acc.tentative += child.attendance?.tentative || 0;
|
|
||||||
acc.invited += child.attendance?.invited || 0;
|
|
||||||
acc.declined += child.attendance?.declined || 0;
|
|
||||||
acc.considered += child.attendance?.considered || 0;
|
|
||||||
acc.total += child.attendance?.total || 0;
|
|
||||||
return acc;
|
|
||||||
}, { confirmed: 0, tentative: 0, invited: 0, declined: 0, considered: 0, total: 0 });
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: group.id,
|
|
||||||
key: group.id,
|
|
||||||
label: group.name,
|
|
||||||
data: {
|
|
||||||
name: group.name,
|
|
||||||
color: <div className="w-8 h-8 rounded-full" style={{ backgroundColor: group.color }} />,
|
|
||||||
confirmed: childrenAttendance.confirmed + (group.attendance?.confirmed || 0),
|
|
||||||
tentative: childrenAttendance.tentative + (group.attendance?.tentative || 0),
|
|
||||||
pending: childrenAttendance.invited + (group.attendance?.invited || 0),
|
|
||||||
declined: childrenAttendance.declined + (group.attendance?.declined || 0),
|
|
||||||
considered: childrenAttendance.considered + (group.attendance?.considered || 0),
|
|
||||||
total: childrenAttendance.total + (group.attendance?.total || 0),
|
|
||||||
actions: actions(group),
|
|
||||||
},
|
|
||||||
children: group.children?.map(renderTree),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodes: TreeNode[] = groups
|
|
||||||
.filter(group => !group.parentId)
|
|
||||||
.map(renderTree)
|
|
||||||
|
|
||||||
const headers = ['Name', 'Color', 'Confirmed', 'Tentative', 'Pending', 'Declined', 'Considered', 'Total', 'Actions'];
|
|
||||||
const rowClassName = () => {
|
|
||||||
return { 'border-b odd:bg-white even:bg-gray-50 hover:bg-gray-100': true };
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<TableOfContents
|
||||||
<TreeTable value={nodes} rowClassName={rowClassName} className='py-4'>
|
headers={['Name', 'Color', 'Confirmed', 'Tentative', 'Pending', 'Declined', 'Considered', 'Total']}
|
||||||
<Column expander field="name" header="Name" className='w-2/5' />
|
caption='Groups'
|
||||||
<Column field="color" header="Color" bodyClassName="text-sm" />
|
elements={groups}
|
||||||
<Column field="confirmed" header="Confirmed" bodyClassName="text-sm" />
|
rowRender={(group) => (
|
||||||
<Column field="tentative" header="Tentative" bodyClassName="text-sm" />
|
<tr key={group.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
|
||||||
<Column field="pending" header="Pending" bodyClassName="text-sm" />
|
<td scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||||
<Column field="declined" header="Declined" bodyClassName="text-sm" />
|
{group.name}
|
||||||
<Column field="considered" header="Considered" bodyClassName="text-sm" />
|
</td>
|
||||||
<Column field="total" header="Total" bodyClassName="text-sm" />
|
<td className="px-6">
|
||||||
<Column field="actions" header="Actions" />
|
<div className="w-8 h-8 rounded-full" style={{ backgroundColor: group.color }}></div>
|
||||||
</TreeTable>
|
</td>
|
||||||
</>
|
<td className="px-6 text-lg">
|
||||||
|
{group.attendance?.confirmed}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 text-sm">
|
||||||
|
{group.attendance?.tentative}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 text-sm">
|
||||||
|
{group.attendance?.invited}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 text-sm">
|
||||||
|
{group.attendance?.declined}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 text-sm">
|
||||||
|
{group.attendance?.considered}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 text-sm">
|
||||||
|
{group.attendance?.total}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
import Skeleton from '@/app/ui/skeleton';
|
import Skeleton from '@/app/ui/skeleton';
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { AbstractApi } from '@/app/api/abstract-api';
|
import { destroyGuest, updateGuest } from '@/app/api/guests';
|
||||||
import { Guest , GuestSerializer} from '@/app/lib/guest';
|
import { Guest, GuestStatus } from '@/app/lib/definitions';
|
||||||
|
import { classNames } from '@/app/ui/components/button';
|
||||||
import { PencilIcon, TrashIcon } from '@heroicons/react/24/outline';
|
import { PencilIcon, TrashIcon } from '@heroicons/react/24/outline';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import TableOfContents from '../components/table-of-contents';
|
import TableOfContents from '../components/table-of-contents';
|
||||||
@ -13,10 +14,6 @@ export default function guestsTable({ guests, onUpdate, onEdit }: {
|
|||||||
onUpdate: () => void,
|
onUpdate: () => void,
|
||||||
onEdit: (guest: Guest) => void
|
onEdit: (guest: Guest) => void
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
const api = new AbstractApi<Guest>();
|
|
||||||
const serializer = new GuestSerializer();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableOfContents
|
<TableOfContents
|
||||||
headers={['Name', 'Group', 'Status', 'Actions']}
|
headers={['Name', 'Group', 'Status', 'Actions']}
|
||||||
@ -48,7 +45,7 @@ export default function guestsTable({ guests, onUpdate, onEdit }: {
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div className="flex flex-row items-center">
|
<div className="flex flex-row items-center">
|
||||||
<TrashIcon className='size-6 cursor-pointer' onClick={() => { api.destroy(serializer, guest, onUpdate)}} />
|
<TrashIcon className='size-6 cursor-pointer' onClick={() => { destroyGuest(guest, () => onUpdate()) }} />
|
||||||
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(guest)} />
|
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(guest)} />
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
||||||
|
|
||||||
export default function Skeleton({ className }: { className: string }) {
|
export default function Skeleton({ className }: { className: string }) {
|
||||||
return <div className={`bg-slate-200 motion-safe:animate-pulse rounded ${className}`} />;
|
return <div className={`bg-slate-200 motion-safe:animate-pulse rounded ${className}`} />;
|
||||||
|
19
package.json
19
package.json
@ -8,31 +8,30 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@heroicons/react": "^2.1.4",
|
"@heroicons/react": "^2.1.4",
|
||||||
"@tailwindcss/forms": "^0.5.7",
|
"@tailwindcss/forms": "^0.5.7",
|
||||||
"autoprefixer": "10.4.21",
|
"autoprefixer": "10.4.20",
|
||||||
"bcrypt": "^5.1.1",
|
"bcrypt": "^5.1.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"next": "15.3.1",
|
"next": "15.0.3",
|
||||||
"next-auth": "5.0.0-beta.25",
|
"next-auth": "5.0.0-beta.25",
|
||||||
"postcss": "8.5.3",
|
"postcss": "8.4.49",
|
||||||
"primeicons": "^7.0.0",
|
"primeicons": "^7.0.0",
|
||||||
"primereact": "^10.8.2",
|
"primereact": "^10.8.2",
|
||||||
"react": "19.0.0-rc-f38c22b244-20240704",
|
"react": "19.0.0-rc-f38c22b244-20240704",
|
||||||
"react-dom": "19.0.0-rc-f38c22b244-20240704",
|
"react-dom": "19.0.0-rc-f38c22b244-20240704",
|
||||||
"tailwindcss": "3.4.17",
|
"tailwindcss": "3.4.16",
|
||||||
"typescript": "5.8.3",
|
"typescript": "5.7.2",
|
||||||
"use-debounce": "^10.0.1",
|
"use-debounce": "^10.0.1",
|
||||||
"uuid": "11.1.0",
|
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.46.0",
|
"@playwright/test": "^1.46.0",
|
||||||
"@types/bcrypt": "^5.0.2",
|
"@types/bcrypt": "^5.0.2",
|
||||||
"@types/node": "22.14.1",
|
"@types/node": "22.10.1",
|
||||||
"@types/react": "18.3.20",
|
"@types/react": "18.3.12",
|
||||||
"@types/react-dom": "18.3.6"
|
"@types/react-dom": "18.3.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=23.0.0"
|
"node": ">=23.0.0"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@9.15.9+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531"
|
"packageManager": "pnpm@9.14.4+sha512.c8180b3fbe4e4bca02c94234717896b5529740a6cbadf19fa78254270403ea2f27d4e1d46a08a0f56c89b63dc8ebfd3ee53326da720273794e6200fcf0d184ab"
|
||||||
}
|
}
|
||||||
|
581
pnpm-lock.yaml
generated
581
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user