-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added blacklist hook * black list feature works * some unused stuff removal * waitlist seems to work * simplified removeBlacklist.js * pretty * removed transaction and hope that it works * fixed useBlackList.js hook firestore error, and made blacklist check functional * added refresh spinner for chooseTeam.js * updated invalidateKeys and fixed some styling * updated faulty invalidateKeys lists * kinda works lmao * updated the invalidateKeys again * navigation off chooseTeam works. Tech debt +1 * half finished progress * invite works * added waitlistError to ErrorComponent * pretty * text input moves above keyboard now * minor comment change Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * changed console log wording in removeBlacklist Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * removed copied over comment * updated tiny comment Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * removed redundant log Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * fix - added email to blacklist record * fix - added assertion if pfp exists when removing a user * can't invite already invited email * accepting invite will remove the invite * added invitelist bug fix * redundant comment Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * :/ Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> * prevent double navigation to chooseTeam screen * fixed "invalid-argument" * added key * Fixed Android keyboard avoiding for invitelist * removed redundant remove user fix * pretty * pretty * pretty * pretty * pretty * added missing state from merge * simple fix * better align invite input with above elements --------- Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com> Co-authored-by: Jake Gehrke <gehrkej@oregonstate.edu>
- Loading branch information
1 parent
65b8beb
commit b2e5a6a
Showing
11 changed files
with
276 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ ios | |
android | ||
webstorm.config.js | ||
firebaseApiKey.js | ||
/.git-branches.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { useMemo, useState } from "react"; | ||
import { | ||
KeyboardAvoidingView, | ||
Platform, | ||
ScrollView, | ||
Text, | ||
TextInput, | ||
View, | ||
} from "react-native"; | ||
import { Button, List } from "react-native-paper"; | ||
import { themeColors } from "~/Constants"; | ||
import { getErrorString } from "~/Utility"; | ||
import ErrorComponent from "~/components/errorComponent"; | ||
import Loading from "~/components/loading"; | ||
import RefreshInvalidate from "~/components/refreshInvalidate"; | ||
import { useAuthContext } from "~/context/Auth"; | ||
import { addToInvitelist } from "~/dbOperations/addToInvitelist"; | ||
import { useInvitelist } from "~/dbOperations/hooks/useInviteList"; | ||
import { invalidateMultipleKeys } from "~/dbOperations/invalidateMultipleKeys"; | ||
import { removeInvitelist } from "~/dbOperations/removeInvitelist"; | ||
|
||
export function Invitelist() { | ||
const { | ||
data: invitelist, | ||
error: inviteError, | ||
isLoading: inviteIsLoading, | ||
} = useInvitelist(); | ||
|
||
const queryClient = useQueryClient(); | ||
|
||
const { currentTeamId } = useAuthContext(); | ||
|
||
const invitedEmail = useMemo(() => { | ||
if (invitelist) | ||
return Object.values(invitelist).map((invite) => invite["email"]); | ||
}, [invitelist]); | ||
|
||
const invalidateKeys = [["invitelist"]]; | ||
|
||
const [currentEmailInput, setCurrentEmailInput] = useState(""); | ||
const [currentEmailValid, setCurrentEmailValid] = useState(false); | ||
const [statusText, setStatusText] = useState(""); | ||
|
||
const onInvite = async () => { | ||
if (invitedEmail.includes(currentEmailInput)) { | ||
setStatusText("Email already invited"); | ||
return; | ||
} | ||
await addToInvitelist(currentTeamId, currentEmailInput); | ||
setCurrentEmailInput(""); | ||
await invalidateMultipleKeys(queryClient, invalidateKeys); | ||
}; | ||
|
||
if (inviteError) { | ||
return <ErrorComponent error={getErrorString(inviteError)} />; | ||
} | ||
|
||
if (inviteIsLoading) { | ||
return <Loading />; | ||
} | ||
|
||
const emailRegex = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w\w+)+$/; | ||
|
||
return ( | ||
<KeyboardAvoidingView | ||
style={{ | ||
flex: 1, | ||
}} | ||
behavior={Platform.OS === "ios" ? "padding" : "height"} | ||
> | ||
<ScrollView | ||
refreshControl={<RefreshInvalidate invalidateKeys={invalidateKeys} />} | ||
> | ||
<List.Section | ||
style={{ | ||
margin: 5, | ||
borderRadius: 5, | ||
}} | ||
> | ||
{Object.keys(invitelist).map((inviteId) => { | ||
return ( | ||
<List.Item | ||
title={invitelist[inviteId].email} | ||
key={inviteId} | ||
right={() => ( | ||
<View | ||
style={{ | ||
flexDirection: "row", | ||
alignItems: "center", | ||
paddingLeft: 10, | ||
}} | ||
> | ||
<Button | ||
onPress={async () => { | ||
await removeInvitelist(currentTeamId, inviteId); | ||
await invalidateMultipleKeys( | ||
queryClient, | ||
invalidateKeys, | ||
); | ||
}} | ||
textColor={themeColors.accent} | ||
> | ||
Remove | ||
</Button> | ||
</View> | ||
)} | ||
/> | ||
); | ||
})} | ||
</List.Section> | ||
</ScrollView> | ||
<Text>{statusText}</Text> | ||
<View | ||
style={{ | ||
flexDirection: "row", | ||
padding: 5, | ||
paddingLeft: 20, | ||
paddingRight: 35, | ||
}} | ||
> | ||
<TextInput | ||
value={currentEmailInput} | ||
onChangeText={(text) => { | ||
setCurrentEmailInput(text); | ||
const included = invitedEmail.includes(text); | ||
if (included) setStatusText("Email already invited"); | ||
else setStatusText(""); | ||
|
||
setCurrentEmailValid(!included && emailRegex.test(text)); | ||
}} | ||
autoCapitalize={"none"} | ||
autoComplete={"email"} | ||
autoCorrect={false} | ||
inputMode={"email"} | ||
keyboardType={"email-address"} | ||
placeholder={"Enter email to invite"} | ||
style={{ | ||
flexGrow: 1, | ||
}} | ||
/> | ||
<Button | ||
disabled={!currentEmailValid} | ||
onPress={onInvite} | ||
textColor={themeColors.accent} | ||
> | ||
Invite | ||
</Button> | ||
</View> | ||
</KeyboardAvoidingView> | ||
); | ||
} | ||
|
||
export default Invitelist; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { collection, doc, setDoc } from "firebase/firestore"; | ||
import { db } from "~/firebaseConfig"; | ||
|
||
export async function addToInvitelist(currentTeamId, email) { | ||
try { | ||
const newRequestRef = doc( | ||
collection(db, "teams", currentTeamId, "invitelist"), | ||
); | ||
await setDoc(newRequestRef, { email }); | ||
} catch (e) { | ||
console.log("Add to Waitlist failed: ", e); | ||
throw e; // Rethrow the error to handle it at the caller's level if needed | ||
} | ||
} |
Oops, something went wrong.