Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed invalid phone param for invite user/createMembership logic #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Logic/Membership/CreateMembership.logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
42 changes: 15 additions & 27 deletions src/components/UserList.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ function UserList({
const [filteredUsers, setFilteredUsers] = useState(null);
const { pathname } = useLocation();





const { sendNotification } = useNotifications();
const { approveRsvp, rejectRsvp } = RsvpLogic();

Expand All @@ -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 || "") ||
Expand All @@ -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;
};

Expand All @@ -91,7 +82,6 @@ function UserList({
};

const handleInvite = async (user, role) => {

const fromUser = JSON.parse(localStorage.getItem("spotlight-user"));
try {
if (typeof createMembership === "function") {
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -148,7 +138,6 @@ function UserList({
}
}
} catch (err) {

toast.error(err.message);
} finally {
}
Expand All @@ -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");
Expand Down Expand Up @@ -272,7 +261,7 @@ function UserList({
}}
onClick={async (e) => {
e?.preventDefault();

toast.custom((t) =>
typeof createMembership === "function" ? (
<form
Expand All @@ -282,7 +271,7 @@ function UserList({
const formData = Object.fromEntries(
new FormData(form)
);

await handleInvite(u, formData.role);
toast.dismiss(t.id);
}}
Expand Down Expand Up @@ -427,14 +416,13 @@ function UserList({
Query.equal("userId", 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
);

}
const owner = users?.find((u) =>
u?.roles?.includes("owner")
Expand Down