-
Notifications
You must be signed in to change notification settings - Fork 2
Remove console.log instances in the app #58
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
base: main
Are you sure you want to change the base?
Changes from all commits
5a10604
926f1fc
1c472e5
217c2c0
7a21efa
25624b4
ac459ee
957e026
0105069
40e46ac
2684c7e
8ff31cf
3ed340f
5f1f91b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,77 +60,76 @@ export default function AddMemberForm({ user }: { user: any }) { | |||||||
|
|
||||||||
| React.useEffect(() => { | ||||||||
| async function fetchMemberGroups() { | ||||||||
| const { data, error } = await supabase | ||||||||
| .from("member_groups") | ||||||||
| .select() | ||||||||
| .eq("created_by", user.id); | ||||||||
| if (error) { | ||||||||
| try { | ||||||||
| const { data, error } = await supabase | ||||||||
| .from("member_groups") | ||||||||
| .select() | ||||||||
| .eq("created_by", user.id); | ||||||||
| if (error) { | ||||||||
| console.error("Error fetching member groups:", error); | ||||||||
| } else { | ||||||||
|
|
||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| setSelectedGroups(null); | ||||||||
| setMemberGroups(data); | ||||||||
| } | ||||||||
| } catch (error) { | ||||||||
| console.error("Error fetching member groups:", error); | ||||||||
|
Comment on lines
+75
to
76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } else { | ||||||||
| console.log("member groups", data); | ||||||||
| setSelectedGroups(null); | ||||||||
| setMemberGroups(data); | ||||||||
| } | ||||||||
| } | ||||||||
| fetchMemberGroups(); | ||||||||
| }, [supabase, submitted]); | ||||||||
| fetchMemberGroups(); | ||||||||
| }, [supabase, submitted]); | ||||||||
|
|
||||||||
| interface MemberGroup { | ||||||||
| id: number; | ||||||||
| name: string; | ||||||||
| } | ||||||||
| interface MemberGroup { | ||||||||
| id: number; | ||||||||
| name: string; | ||||||||
| } | ||||||||
|
|
||||||||
| async function onSubmit(data: MemberFormValues) { | ||||||||
| console.log("DATA", selectedGroups); | ||||||||
| try { | ||||||||
| // Get the IDs of the selected groups that already exist in memberGroups | ||||||||
| const existingGroupIds = selectedGroups | ||||||||
| ?.filter((group) => | ||||||||
| memberGroups?.map(({ name }) => name).includes(group.value) | ||||||||
| ) | ||||||||
| .map( | ||||||||
| (group) => memberGroups.find(({ name }) => name === group.value)?.id | ||||||||
| ); | ||||||||
| async function onSubmit(data: MemberFormValues) { | ||||||||
| try { | ||||||||
| // Get the IDs of the selected groups that already exist in memberGroups | ||||||||
| const existingGroupIds = selectedGroups | ||||||||
| ?.filter((group) => | ||||||||
| memberGroups?.map(({ name }) => name).includes(group.value) | ||||||||
| ) | ||||||||
| .map( | ||||||||
| (group) => memberGroups.find(({ name }) => name === group.value)?.id | ||||||||
| ); | ||||||||
|
|
||||||||
| // let groupIds = []; | ||||||||
| // groupIds = groupIds.concat(existingGroupIds); | ||||||||
| // let groupIds = []; | ||||||||
| // groupIds = groupIds.concat(existingGroupIds); | ||||||||
|
|
||||||||
| // Add the IDs of the existing groups to groupIds | ||||||||
| console.log("memberGroups", memberGroups); | ||||||||
| // Check if the selectedGroups exists in memberGroups | ||||||||
| const newGroups = | ||||||||
| selectedGroups | ||||||||
| // Add the IDs of the existing groups to groupIds | ||||||||
| // console.log("memberGroups", memberGroups); | ||||||||
| // console.log("newgroups", newGroups); | ||||||||
|
Comment on lines
+101
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| // Check if the selectedGroups exists in memberGroups | ||||||||
| const newGroups = | ||||||||
| ?.filter( | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| (group) => | ||||||||
| !memberGroups?.map(({ name }) => name).includes(group.value) | ||||||||
| ) | ||||||||
| .map(({ value }) => value) || []; | ||||||||
|
|
||||||||
| console.log("newgroups", newGroups); | ||||||||
|
|
||||||||
| // groupIds = selectedGroups?.map((group) => group.value); | ||||||||
| // groupIds = selectedGroups?.map((group) => group.value); | ||||||||
|
|
||||||||
| // If selectedGroups doesn't exist, create a new group | ||||||||
| let groupIds = []; | ||||||||
| if (!!newGroups.length) { | ||||||||
| const groupResponse = await supabase | ||||||||
| .from("member_groups") | ||||||||
| .insert(newGroups.map((name) => ({ name, created_by: user.id }))) | ||||||||
| .select(); | ||||||||
| console.log("gr", groupResponse); | ||||||||
| const { data: createdGroups, error: createGroupError } = groupResponse; | ||||||||
| console.log("created groups", createdGroups); | ||||||||
| if (createGroupError) { | ||||||||
| console.error("Error creating new group:", createGroupError); | ||||||||
| } else { | ||||||||
| if (Array.isArray(createdGroups) && createdGroups.length > 0) { | ||||||||
| groupIds = createdGroups.map(({ id }) => id); | ||||||||
| // If selectedGroups doesn't exist, create a new group | ||||||||
| let groupIds = []; | ||||||||
| if (!!newGroups.length) { | ||||||||
| .from("member_groups") | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| .insert(newGroups.map((name) => ({ name, created_by: user.id }))) | ||||||||
| .select(); | ||||||||
|
|
||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| const { data: createdGroups, error: createGroupError } = groupResponse; | ||||||||
| console.log("created groups", createdGroups); | ||||||||
| if (createGroupError) { | ||||||||
| console.error("Error creating new group:", createGroupError); | ||||||||
| } else { | ||||||||
| if (Array.isArray(createdGroups) && createdGroups.length > 0) { | ||||||||
| groupIds = createdGroups.map(({ id }) => id); | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // Create the new member | ||||||||
| const memberUpdates = { | ||||||||
| // Create the new member | ||||||||
| const memberUpdates = { | ||||||||
| email: data.email, | ||||||||
| first_name: data.first_name, | ||||||||
| last_name: data.last_name, | ||||||||
|
|
@@ -144,10 +143,9 @@ export default function AddMemberForm({ user }: { user: any }) { | |||||||
| .select(); | ||||||||
| if (memberError) { | ||||||||
| throw memberError; | ||||||||
| } | ||||||||
| const memberID = newMember[0].id; | ||||||||
| } const memberID = newMember[0].id; | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| console.log("SELECT", selectedGroups); | ||||||||
|
|
||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete newline
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Wrote ChangesDone. |
||||||||
|
|
||||||||
| // Update the joins table to associate the member with the group | ||||||||
| if (!!selectedGroups?.length && memberID) { | ||||||||
|
|
@@ -177,10 +175,9 @@ export default function AddMemberForm({ user }: { user: any }) { | |||||||
| toast({ | ||||||||
| description: "Your member has been added", | ||||||||
| }); | ||||||||
| setSubmitted(true); | ||||||||
| router.refresh(); | ||||||||
| setSubmitted(true); router.refresh(); | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } catch (error) { | ||||||||
| console.log(error); | ||||||||
|
|
||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete newline
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Wrote ChangesDone. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -273,7 +270,7 @@ export default function AddMemberForm({ user }: { user: any }) { | |||||||
| }))} // Convert memberGroups to options | ||||||||
| value={selectedGroups} | ||||||||
| onChange={(value) => { | ||||||||
| console.log("creatable value", value); | ||||||||
| // console.log("creatable value", value); | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| setSelectedGroups(value); | ||||||||
| }} | ||||||||
| /> | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -76,7 +76,6 @@ export default function EditMemberForm({ | |||
| if (error) { | ||||
| console.error("Error fetching member groups:", error); | ||||
| } else { | ||||
| console.log("member groups", data); | ||||
| setMemberGroups(data); | ||||
| } | ||||
| } | ||||
|
|
@@ -106,123 +105,120 @@ export default function EditMemberForm({ | |||
| } | ||||
| }, [existingGroups]); | ||||
|
|
||||
| console.log("Select", selectedGroups); | ||||
| console.log("EIT", existingGroups); | ||||
| const existingGroupIds = existingGroups ? existingGroups.split(",") : []; | ||||
|
|
||||
| console.log("existingIDs", existingGroupIds); | ||||
| // console.log("existingIDs", existingGroupIds); | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| async function onSubmit(data: MemberFormValues) { | ||||
| const { | ||||
| data: { user }, | ||||
| } = await supabase.auth.getUser(); | ||||
| let groupIds = []; | ||||
| // Delete all existing associations for the member | ||||
| const { error: deleteError } = await supabase | ||||
| const { | ||||
| data: { user }, | ||||
| } = await supabase.auth.getUser(); | ||||
|
|
||||
| let groupIds = []; | ||||
|
|
||||
| // Delete all existing associations for the member | ||||
| const { error: deleteError } = await supabase | ||||
| .from("member_group_joins") | ||||
| .delete() | ||||
| .eq("member_id", member.id); | ||||
| if (deleteError) { | ||||
| if (deleteError) { | ||||
| console.error("Error deleting existing associations:", deleteError); | ||||
| } | ||||
|
|
||||
| // Get the IDs of the selected groups that already exist in memberGroups | ||||
| // Get the IDs of the selected groups that already exist in memberGroups | ||||
| const existingGroupIds = selectedGroups | ||||
| ?.filter((group) => | ||||
| memberGroups?.map(({ name }) => name).includes(group.value) | ||||
| } | ||||
|
|
||||
| // Get the IDs of the selected groups that already exist in memberGroups | ||||
| // Get the IDs of the selected groups that already exist in memberGroups | ||||
| ?.filter( | ||||
| (group) => memberGroups?.map(({ name }) => name).includes(group.value), | ||||
| ) | ||||
| .map( | ||||
| (group) => memberGroups.find(({ name }) => name === group.value)?.id, | ||||
| ); | ||||
|
|
||||
| // Add the IDs of the existing groups to groupIds | ||||
|
|
||||
| // Save new groups - if the member group doesn't hold any of the selected groups | ||||
| const newGroups = | ||||
| selectedGroups | ||||
| ?.filter( | ||||
| (group) => | ||||
| !memberGroups?.map(({ name }) => name).includes(group.value), | ||||
| ) | ||||
| .map((group) => memberGroups.find(({ name }) => name === group.value)?.id); | ||||
|
|
||||
| // Add the IDs of the existing groups to groupIds | ||||
|
|
||||
| // Save new groups - if the member group doesn't hold any of the selected groups | ||||
| const newGroups = | ||||
| selectedGroups | ||||
| ?.filter( | ||||
| (group) => | ||||
| !memberGroups?.map(({ name }) => name).includes(group.value) | ||||
| ) | ||||
| .map(({ value }) => value) || []; | ||||
|
|
||||
| //Creating a new group if there are elements in the newgroup array | ||||
| if (!!newGroups.length) { | ||||
| const groupResponse = await supabase | ||||
| .from("member_groups") | ||||
| .insert(newGroups.map((name) => ({ name }))) | ||||
| .select(); | ||||
| console.log("gr", groupResponse); | ||||
| const { data: createdGroups, error: createGroupError } = groupResponse; | ||||
| console.log("created groups", createdGroups); | ||||
| if (createGroupError) { | ||||
| console.error("Error creating new group:", createGroupError); | ||||
| } else { | ||||
| if (Array.isArray(createdGroups) && createdGroups.length > 0) { | ||||
| groupIds = createdGroups.map(({ id }) => id); | ||||
| } | ||||
| .map(({ value }) => value) || []; | ||||
|
|
||||
| //Creating a new group if there are elements in the newgroup array | ||||
| if (!!newGroups.length) { | ||||
| const groupResponse = await supabase | ||||
| .from("member_groups") | ||||
| .insert(newGroups.map((name) => ({ name }))) | ||||
| .select(); | ||||
| const { data: createdGroups, error: createGroupError } = groupResponse; | ||||
| console.log("created groups", createdGroups); | ||||
| if (createGroupError) { | ||||
| console.error("Error creating new group:", createGroupError); | ||||
| } else { | ||||
| if (Array.isArray(createdGroups) && createdGroups.length > 0) { | ||||
| groupIds = createdGroups.map(({ id }) => id); | ||||
| } | ||||
| } | ||||
|
|
||||
| try { | ||||
| const updates = { | ||||
| email: data.email, | ||||
| first_name: data.first_name, | ||||
| last_name: data.last_name, | ||||
| created_by: user?.id, | ||||
| }; | ||||
|
|
||||
| const selectedGroupIds = selectedGroups | ||||
| ? selectedGroups.map((group) => group.value) | ||||
| : []; | ||||
|
|
||||
| console.log("SId", selectedGroupIds); | ||||
| if (!!selectedGroups?.length && member.id) { | ||||
| // Insert new associations | ||||
| const joinUpdates = selectedGroups | ||||
| } | ||||
| } | ||||
|
|
||||
| try { | ||||
| const updates = { | ||||
| email: data.email, | ||||
| first_name: data.first_name, | ||||
| last_name: data.last_name, | ||||
| created_by: user?.id, | ||||
| }; | ||||
|
|
||||
| const selectedGroupIds = selectedGroups | ||||
| ? selectedGroups.map((group) => group.value) | ||||
| : []; | ||||
|
|
||||
|
|
||||
| if (!!selectedGroups?.length && member.id) { | ||||
| // Insert new associations | ||||
| const joinUpdates = selectedGroups | ||||
| ?.map((group) => memberGroups.find((g) => g.name === group.value)?.id) | ||||
| .concat(groupIds) | ||||
| .filter((id) => id !== undefined) | ||||
| .map((memberGroupId) => ({ | ||||
| member_id: member.id, | ||||
| group_id: memberGroupId, | ||||
| })); | ||||
|
|
||||
| const { error: joinError } = await supabase | ||||
| .from("member_group_joins") | ||||
| .insert(joinUpdates); | ||||
| if (joinError) { | ||||
| console.error("Error updating member_group_joins:", joinError); | ||||
| } | ||||
| } | ||||
| let { error } = await supabase | ||||
| .from("members") | ||||
| .update(updates) | ||||
| .eq("id", member.id); | ||||
| if (error) { | ||||
| toast({ | ||||
| description: "An error occurred while updating the member", | ||||
| }); | ||||
| } else { | ||||
| toast({ | ||||
| description: "Your member has been updated", | ||||
| }); | ||||
| router.refresh(); | ||||
|
|
||||
| const { error: joinError } = await supabase | ||||
| .from("member_group_joins") | ||||
| .insert(joinUpdates); | ||||
| if (joinError) { | ||||
| console.error("Error updating member_group_joins:", joinError); | ||||
| } | ||||
| } catch (error) { | ||||
| } | ||||
| let { error } = await supabase | ||||
| .from("members") | ||||
| .update(updates) | ||||
| .eq("id", member.id); | ||||
| if (error) { | ||||
| toast({ | ||||
| description: "An error occurred while updating the member", | ||||
| }); | ||||
| } else { | ||||
| toast({ | ||||
| description: "Your member has been updated", | ||||
| }); | ||||
| router.refresh(); | ||||
| } | ||||
| } catch (error) { | ||||
| toast({ | ||||
| description: "An error occurred while updating the member", | ||||
| }); | ||||
| } | ||||
| } | ||||
|
|
||||
| // React.useEffect(() => { | ||||
| // async function fetchMemberGroups() { | ||||
| // const { data, error } = await supabase.from("member_groups").select(); | ||||
| // if (error) { | ||||
| // console.error("Error fetching member groups:", error); | ||||
| // } else { | ||||
| // console.log("gr", groupResponse); | ||||
| // console.log("created groups", createdGroups); | ||||
|
Comment on lines
-224
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert these changes |
||||
| // console.log("member groups", data); | ||||
| // setMemberGroups(data); | ||||
| // } | ||||
|
|
@@ -314,7 +310,7 @@ export default function EditMemberForm({ | |||
| }))} | ||||
| value={selectedGroups} | ||||
| onChange={(value) => { | ||||
| console.log("creatable value", value); | ||||
| // console.log("creatable value", value); | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| setSelectedGroups(value); | ||||
| }} | ||||
| /> | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.