-
Notifications
You must be signed in to change notification settings - Fork 0
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
IWB-5: Added invite tab #300
Changes from all commits
8ca9933
657384e
296e07d
ac7e815
0853aa4
999af90
9fa672f
5c66aba
f5a1855
7c7625d
ca85173
852c832
b9c50ef
4f5ac10
d3fd882
72c08a6
6ea881f
6ac7af1
ed8f8db
07142cd
872e3ce
817972a
3b1463a
52b16f8
edee24f
8fb3f94
91ab448
baa4e90
8183b22
6415dfe
54469bf
ddc53cc
12dc38f
eb76078
f763731
91cea9e
51e60d3
0fba67e
3e5a65e
06963df
3f52e48
180b096
dfddbc0
d54e5c1
2743407
46f85e9
f983bbf
c9c8fbf
5e1dc1b
49b040e
2055022
0f4459b
fe9e79e
3872b6f
b3481a3
de580e8
3ce1c25
02c7865
35a5a26
1ae93ef
f869cfb
30081f4
340cb4d
b5ed7d8
a066201
067f6b4
6d3fdd7
45e627d
cfd9e15
6bff91c
a6dcbc8
89b82c9
6c48415
58d3865
8dab777
87e7e80
605472b
7619df3
ab422e6
4bfbaab
4204c74
3cf56c3
fe94315
d20d3dd
cc97e8c
d1413af
553300c
06c7b91
db00910
35cd182
59ec3cf
eb74065
326dc00
71823f0
364abe7
c8d412e
dd31a1f
57ef84e
b0ddd79
68aad1c
c6aba50
18d78ca
9048f77
a030a08
d9b2ab3
f129a8f
fbee72c
16df1e7
41f1613
ffb514b
118684e
8951322
5fe346d
b76cba6
e1971d6
b6b0018
310b3f9
d6aaba8
e924029
2da6b41
9737dc3
fca54a9
e342ea5
8564bcf
307bc50
eec6a3b
3c2d9a2
92af713
0d44915
e6c5e8a
fe33609
d6b73b3
a094d4c
8e4c349
2194eb3
a67a223
189ecdc
3e944d5
af682fc
de570e5
d0b040e
65ff8f0
cd94dc2
bbaf4fa
1d28b0f
93a7cb2
c2104b9
e54fe2e
9daf486
75af2f7
21620ef
1ea9cfe
1440550
cd8393d
0503312
c82967a
5417279
1554f1c
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ ios | |
android | ||
webstorm.config.js | ||
firebaseApiKey.js | ||
/.git-branches.toml |
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 | ||
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. 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. It fixes when you start typing but on the first click it looks like this 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. fixed! |
||
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; |
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 | ||
} | ||
} |
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.
Shoud clicking this button when a player is invited remove them from the invite list? The list might get a little crowded if it doesn't. I tested this with "Roman Wilson" and upon joining the invite is still there
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.
I've just added a feature where if a player joined using an invitation, the invite will be removed. Otherwise I don't quite understand your question. Clicking "Remove" should remove the invitation