From ad2a69e6fefad1076607dcf2ff4414db15db4511 Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Tue, 14 May 2024 16:52:40 +0200 Subject: [PATCH] feat(app): users are now all stored in a users table and more list settings are available --- README.md | 3 +- .../auth/{LdapUserInput.tsx => UserInput.tsx} | 8 +-- ...{LdapUsersDisplay.tsx => UsersDisplay.tsx} | 10 ++-- .../auth/modals/ChangeEmailModal.tsx | 9 ++-- .../auth/modals/EmailTokenVerification.tsx | 9 ++-- .../auth/modals/ForgotPasswordModal.tsx | 8 +-- src/components/auth/modals/LoginModal.tsx | 4 +- src/components/auth/modals/RegisterModal.tsx | 9 ++-- src/components/auth/modals/UserMenuModal.tsx | 50 +++++++++++++------ src/components/auth/modals/util.tsx | 40 +++++++++++++++ src/components/layout/nav/MenuItems.tsx | 25 ++++++++-- src/components/layout/nav/index.tsx | 4 +- src/lib/pocketbase.tsx | 8 ++- src/lib/user.ts | 27 ---------- src/models/AuthTypes.ts | 32 +++++++----- src/models/EventTypes.ts | 22 ++++---- src/models/index.ts | 6 +-- .../events/EventOverview/CreateEvent.tsx | 12 ++--- src/pages/events/EventOverview/index.page.tsx | 15 ++++-- .../e/:eventId/EventComponents/EventData.tsx | 6 +-- .../EventSettings/EditEventMembers.tsx | 16 +++--- .../EventLists/:listId/EventListRouter.tsx | 28 +++++++++-- .../EventListSettings/EventListSettings.tsx | 49 ++++++++++++------ .../EventListSlotEntriesTable.tsx | 7 +-- .../EventListSlotEntryRow.tsx | 5 +- .../EventListSearch/EventListSearchResult.tsx | 3 +- .../EventLists/EventListSearch/index.tsx | 15 +++--- .../components/EditSlotEntryMenu.tsx | 3 +- .../MoveEventListSlotEntryModal.tsx | 5 +- .../UpdateEventListSlotEntryFormModal.tsx | 5 +- .../UpdateEventListSlotEntryStatusModal.tsx | 5 +- .../components/UpsertEventListSlot.tsx | 11 ++-- src/pages/events/entries/UserEntries.tsx | 21 ++++---- src/pages/events/entries/UserEntryRow.tsx | 7 +-- src/pages/events/s/EventListSlotView.tsx | 20 ++++---- src/pages/events/s/EventListView.tsx | 19 ++++++- src/pages/events/s/EventView.tsx | 4 +- src/pages/events/util.ts | 11 ++-- src/pages/home/index.page.tsx | 9 ++-- 39 files changed, 334 insertions(+), 216 deletions(-) rename src/components/auth/{LdapUserInput.tsx => UserInput.tsx} (80%) rename src/components/auth/{LdapUsersDisplay.tsx => UsersDisplay.tsx} (51%) create mode 100644 src/components/auth/modals/util.tsx delete mode 100644 src/lib/user.ts diff --git a/README.md b/README.md index af9c1ac..0625fd9 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,7 @@ Dieser Client ist ein React Hook und kann in jeder React Komponente verwendet we import {usePB} from "@/lib/pocketbase" import {useQuery} from "@tanstack/react-query"; -const {pb} = usePB() -const user = useUser() +const {pb,user} = usePB() const query = useQuery({ queryKey: ["collection", id], diff --git a/src/components/auth/LdapUserInput.tsx b/src/components/auth/UserInput.tsx similarity index 80% rename from src/components/auth/LdapUserInput.tsx rename to src/components/auth/UserInput.tsx index 711890b..17e4b13 100644 --- a/src/components/auth/LdapUserInput.tsx +++ b/src/components/auth/UserInput.tsx @@ -1,17 +1,17 @@ import {useMutation} from "@tanstack/react-query"; import {IconUsers} from "@tabler/icons-react"; import {usePB} from "@/lib/pocketbase.tsx"; -import {LdapUserModel} from "@/models/AuthTypes.ts"; +import {UserModal} from "@/models/AuthTypes.ts"; import RecordSearchInput, {GenericRecordSearchInputProps} from "../input/RecordSearchInput.tsx"; -export default function LdapUserInput(props: GenericRecordSearchInputProps) { +export default function UserInput(props: GenericRecordSearchInputProps) { const {pb} = usePB() return ( + recordToString={(user) => ({displayName: `${user.givenName} ${user.sn}`})} {...props} placeholder={props.placeholder || "Suche nach Personen..."} @@ -23,7 +23,7 @@ export default function LdapUserInput(props: GenericRecordSearchInputProps s.trim()).join(".") }%")`, diff --git a/src/components/auth/LdapUsersDisplay.tsx b/src/components/auth/UsersDisplay.tsx similarity index 51% rename from src/components/auth/LdapUsersDisplay.tsx rename to src/components/auth/UsersDisplay.tsx index 69fc7dc..e2dd226 100644 --- a/src/components/auth/LdapUsersDisplay.tsx +++ b/src/components/auth/UsersDisplay.tsx @@ -1,18 +1,18 @@ -import {LdapUserModel} from "@/models/AuthTypes.ts"; +import {UserModal} from "@/models/AuthTypes.ts"; import {List} from "@mantine/core"; import {IconUser} from "@tabler/icons-react"; import {usePB} from "@/lib/pocketbase.tsx"; -export default function LdapUsersDisplay({users}: { users: LdapUserModel[] }) { +export default function UsersDisplay({users}: { users: UserModal[] }) { - const {ldapUser} = usePB() + const {user} = usePB() return <> }> { users.map((u) => ( - - {u.givenName} {u.sn} + + {u.username} )) } diff --git a/src/components/auth/modals/ChangeEmailModal.tsx b/src/components/auth/modals/ChangeEmailModal.tsx index 2de6495..14f0a99 100644 --- a/src/components/auth/modals/ChangeEmailModal.tsx +++ b/src/components/auth/modals/ChangeEmailModal.tsx @@ -8,7 +8,6 @@ import {showSuccessNotification} from "@/components/util.tsx"; import {useSearchParams} from "react-router-dom"; import EmailSVG from "@/illustrations/email.svg?react" -import {useUser} from "@/lib/user.ts"; import PromptLoginModal from "@/components/auth/modals/PromptLoginModal.tsx"; export const CHANGE_EMAIL_TOKEN_KEY = "changeEmailToken" @@ -31,7 +30,7 @@ const RequestEmailChangeModal = ({open, onClose}: { const mutation = useMutation({ mutationFn: async () => { - await pb.collection("guest_users").requestEmailChange(formValues.values.email) + await pb.collection("users").requestEmailChange(formValues.values.email) }, onSuccess: () => { formValues.reset() @@ -96,7 +95,7 @@ const ConfirmEmailChangeModal = ({open, onClose, token}: { const mutation = useMutation({ mutationFn: async () => { - await pb.collection("guest_users").confirmEmailChange( + await pb.collection("users").confirmEmailChange( token, formValues.values.password, ) @@ -115,7 +114,7 @@ const ConfirmEmailChangeModal = ({open, onClose, token}: {
mutation.mutate())}>
- +
@@ -153,7 +152,7 @@ const ConfirmEmailChangeModal = ({open, onClose, token}: { export default function ChangeEmailModal() { const {value, handler} = useChangeEmail() - const user = useUser() + const {user} = usePB() const [searchParams] = useSearchParams() diff --git a/src/components/auth/modals/EmailTokenVerification.tsx b/src/components/auth/modals/EmailTokenVerification.tsx index c14827b..1835b35 100644 --- a/src/components/auth/modals/EmailTokenVerification.tsx +++ b/src/components/auth/modals/EmailTokenVerification.tsx @@ -6,7 +6,6 @@ import {showErrorNotification, showSuccessNotification} from "@/components/util. import {Alert, Button, Group, Modal, TextInput, Title} from "@mantine/core"; import {IconAt} from "@tabler/icons-react"; import {useLogin} from "@/components/auth/modals/hooks.ts"; -import {useUser} from "@/lib/user.ts"; export const EMAIL_TOKEN_KEY = "emailVerificationToken" @@ -29,13 +28,11 @@ export default function EmailTokenVerification() { const [email, setEmail] = useState("") - const {pb, refreshUser} = usePB() - - const user = useUser() + const {pb, user, refreshUser} = usePB() const verifyTokenMutation = useMutation({ mutationFn: async (token: string) => { - await pb.collection("guest_users").confirmVerification(token) + await pb.collection("users").confirmVerification(token) }, onSuccess: () => { showSuccessNotification("E-Mail erfolgreich verifiziert") @@ -77,7 +74,7 @@ export default function EmailTokenVerification() {