From 2f70b7ceea22d95977bc997e3669108dbd2b65f6 Mon Sep 17 00:00:00 2001 From: Sanjay-Khadka Date: Tue, 27 Feb 2024 20:19:16 +0545 Subject: [PATCH] fix: fixed invalid phone param for invite user/createMembership logic --- .../Membership/CreateMembership.logic.js | 10 ++--- src/components/UserList.js | 42 +++++++------------ 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/Logic/Membership/CreateMembership.logic.js b/src/Logic/Membership/CreateMembership.logic.js index a41ab06..8f8a6f3 100644 --- a/src/Logic/Membership/CreateMembership.logic.js +++ b/src/Logic/Membership/CreateMembership.logic.js @@ -5,16 +5,16 @@ import { Teams, Databases } from "appwrite"; export default function CreateMembershipLogic(teamId) { const [teamMembers, setTeamMembers] = useState(null); const [memberCount, setMemberCount] = useState(null); - + async function createMembership({ eventId, teamId, userId, name, + phone, email, role, }) { - if (typeof role !== "string") { throw new Error("Role must be a string value"); } @@ -25,10 +25,10 @@ export default function CreateMembershipLogic(teamId) { `${process.env.REACT_APP_WEBSITE_URL}/accept-invite/${eventId}`, email, userId, - "", + phone, name ); - + setTeamMembers((prev) => [...prev, res]); setMemberCount((prev) => prev + 1); return res; @@ -39,7 +39,7 @@ export default function CreateMembershipLogic(teamId) { try { const teams = new Teams(client); const res = await teams.listMemberships(teamId); - + setMemberCount((prev) => res.total); setTeamMembers((prev) => res.memberships); } catch (err) { diff --git a/src/components/UserList.js b/src/components/UserList.js index 3e8decc..b621b99 100644 --- a/src/components/UserList.js +++ b/src/components/UserList.js @@ -25,10 +25,6 @@ function UserList({ const [filteredUsers, setFilteredUsers] = useState(null); const { pathname } = useLocation(); - - - - const { sendNotification } = useNotifications(); const { approveRsvp, rejectRsvp } = RsvpLogic(); @@ -51,9 +47,6 @@ function UserList({ (e) => { const value = e.target.value.toLowerCase(); const filtered = users.filter((user) => { - - - return ( (user?.name ?? user?.userName).toLowerCase().includes(value || "") || (user.email ?? user?.userEmail).toLowerCase().includes(value || "") || @@ -74,9 +67,7 @@ function UserList({ const checkUserRoles = (id) => { const userId = JSON.parse(localStorage.getItem("spotlight-user"))?.["$id"]; const user = users?.find((user) => user?.userId === (id ?? userId)); - - - + return user?.roles; }; @@ -91,7 +82,6 @@ function UserList({ }; const handleInvite = async (user, role) => { - const fromUser = JSON.parse(localStorage.getItem("spotlight-user")); try { if (typeof createMembership === "function") { @@ -100,10 +90,11 @@ function UserList({ teamId: events?.teamId, userId: user.userId, name: user.name, + phone: user.phone, email: user.email, role, }); - + toast.success(`${user.name} has been invited to the event`); await sendNotification({ @@ -125,14 +116,13 @@ function UserList({ Query.equal("userId", user?.userId), ] ); - + if (res?.documents?.length > 0) { const delRes = await databases.deleteDocument( process.env.REACT_APP_DATABASE_ID, process.env.REACT_APP_RSVP_COLLECTION_ID, res?.documents[0]?.$id ); - } toast.success("Invitation deleted"); await sendNotification({ @@ -148,7 +138,6 @@ function UserList({ } } } catch (err) { - toast.error(err.message); } finally { } @@ -158,15 +147,15 @@ function UserList({ const sanitizedData = data?.map((user) => { return { "Membarship ID": user?.$id, - "Name": user?.userName, - "Email": user?.userEmail, + Name: user?.userName, + Email: user?.userEmail, "User ID": user?.userId, - "Invited": user?.invited, - "Joined": user?.joined, - "Confirm": user?.confirm, - "Roles": user?.roles?.join(","), - } - }) + Invited: user?.invited, + Joined: user?.joined, + Confirm: user?.confirm, + Roles: user?.roles?.join(","), + }; + }); const worksheet = XLSX.utils.json_to_sheet(sanitizedData); const workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1"); @@ -272,7 +261,7 @@ function UserList({ }} onClick={async (e) => { e?.preventDefault(); - + toast.custom((t) => typeof createMembership === "function" ? (
0) { const delRes = await databases.deleteDocument( process.env.REACT_APP_DATABASE_ID, process.env.REACT_APP_RSVP_COLLECTION_ID, res?.documents[0]?.$id ); - } const owner = users?.find((u) => u?.roles?.includes("owner")