-
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.
IWB-2: added blacklist management functionality (#310)
* added blacklist hook * black list feature works * some unused stuff removal * simplified removeBlacklist.js * removed transaction and hope that it works * fixed useBlackList.js hook firestore error, and made blacklist check functional * added refresh spinner for chooseTeam.js * kinda works lmao * minor comment change Co-authored-by: Jake Gehrke <[email protected]> * changed console log wording in removeBlacklist Co-authored-by: Jake Gehrke <[email protected]> * removed copied over comment * fix - added email to blacklist record * fix - added assertion if pfp exists when removing a user * fixed "invalid-argument" * added key * removed redundant remove user fix * pretty * added missing state from merge * simple fix --------- Co-authored-by: Jake Gehrke <[email protected]> Co-authored-by: Jake Gehrke <[email protected]>
- Loading branch information
1 parent
76fb5c7
commit 2589d27
Showing
5 changed files
with
252 additions
and
52 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
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,72 @@ | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { ScrollView, View } from "react-native"; | ||
import { Button, List } from "react-native-paper"; | ||
import { themeColors } from "~/Constants"; | ||
import ErrorComponent from "~/components/errorComponent"; | ||
import Loading from "~/components/loading"; | ||
import RefreshInvalidate from "~/components/refreshInvalidate"; | ||
import { useAuthContext } from "~/context/Auth"; | ||
import { useBlackList } from "~/dbOperations/hooks/useBlackList"; | ||
import { invalidateMultipleKeys } from "~/dbOperations/invalidateMultipleKeys"; | ||
import { removeBlacklist } from "~/dbOperations/removeBlacklist"; | ||
|
||
function Blacklist() { | ||
const { | ||
data: blacklist, | ||
error: blacklistError, | ||
isLoading: blacklistIsLoading, | ||
} = useBlackList(); | ||
|
||
const { currentTeamId } = useAuthContext(); | ||
|
||
const queryClient = useQueryClient(); // also called here for updating name | ||
|
||
const invalidateKeys = [["blacklist"]]; | ||
|
||
if (blacklistIsLoading) return <Loading />; | ||
|
||
if (blacklistError) return <ErrorComponent errorList={[blacklistError]} />; | ||
|
||
return ( | ||
<ScrollView | ||
refreshControl={<RefreshInvalidate invalidateKeys={invalidateKeys} />} | ||
> | ||
<List.Section | ||
style={{ | ||
margin: 5, | ||
borderRadius: 5, | ||
}} | ||
> | ||
{Object.keys(blacklist).map((userId) => { | ||
return ( | ||
<List.Item | ||
title={blacklist[userId].email} | ||
key={userId} | ||
right={() => ( | ||
<View | ||
style={{ | ||
flexDirection: "row", | ||
alignItems: "center", | ||
paddingLeft: 10, | ||
}} | ||
> | ||
<Button | ||
onPress={async () => { | ||
await removeBlacklist(currentTeamId, userId); | ||
await invalidateMultipleKeys(queryClient, invalidateKeys); | ||
}} | ||
textColor={themeColors.accent} | ||
> | ||
Unban | ||
</Button> | ||
</View> | ||
)} | ||
/> | ||
); | ||
})} | ||
</List.Section> | ||
</ScrollView> | ||
); | ||
} | ||
|
||
export default Blacklist; |
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,99 @@ | ||
import { useNavigation } from "expo-router"; | ||
import { useMemo, useState } from "react"; | ||
import { Appbar, SegmentedButtons } from "react-native-paper"; | ||
import { SafeAreaView } from "react-native-safe-area-context"; | ||
import { themeColors } from "~/Constants"; | ||
import Blacklist from "~/app/segments/(team)/blacklist"; | ||
import Header from "~/components/header"; | ||
|
||
function ManageForeignRequests() { | ||
const [tabValue, setTabValue] = useState("invites"); | ||
const navigation = useNavigation(); | ||
|
||
const segmentedColor = (tab) => { | ||
switch (tab) { | ||
case "invites": | ||
return "#008001"; | ||
case "waitlist": | ||
return "#FFE900"; | ||
case "blacklist": | ||
return "#FE0100"; | ||
default: | ||
return themeColors.overlay; | ||
} | ||
}; | ||
|
||
const segmentedTextColor = (tab) => { | ||
switch (tab) { | ||
case "invites": | ||
case "blacklist": | ||
return "white"; | ||
case "waitlist": | ||
return "black"; | ||
default: | ||
return "black"; | ||
} | ||
}; | ||
|
||
const tabComponent = useMemo( | ||
() => ({ | ||
invites: <></>, | ||
waitlist: <></>, | ||
blacklist: <Blacklist />, | ||
}), | ||
[], | ||
); | ||
|
||
return ( | ||
<SafeAreaView | ||
style={{ | ||
flex: 1, | ||
}} | ||
> | ||
<Header | ||
title="Manage Foreign Requests" | ||
preChildren={ | ||
<Appbar.BackAction | ||
onPress={() => { | ||
navigation.goBack(); | ||
}} | ||
color={themeColors.accent} | ||
/> | ||
} | ||
/> | ||
<SegmentedButtons | ||
value={tabValue} | ||
onValueChange={setTabValue} | ||
style={{ | ||
marginLeft: 10, | ||
marginRight: 10, | ||
backgroundColor: themeColors.highlight, | ||
borderRadius: 20, | ||
}} | ||
theme={{ | ||
colors: { | ||
secondaryContainer: segmentedColor(tabValue), | ||
onSecondaryContainer: segmentedTextColor(tabValue), | ||
}, | ||
}} | ||
buttons={[ | ||
{ | ||
value: "invites", | ||
label: "Invites", | ||
}, | ||
{ | ||
value: "waitlist", | ||
label: "Waitlist", | ||
}, | ||
{ | ||
value: "blacklist", | ||
label: "Blacklist", | ||
}, | ||
]} | ||
/> | ||
{tabComponent[tabValue]} | ||
</SafeAreaView> | ||
); | ||
} | ||
|
||
export default ManageForeignRequests; |
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,13 @@ | ||
import { deleteDoc, doc } from "firebase/firestore"; | ||
import { db } from "~/firebaseConfig"; | ||
|
||
async function removeBlacklist(teamId, userId) { | ||
try { | ||
await deleteDoc(doc(db, "teams", teamId, "blacklist", userId)); | ||
} catch (e) { | ||
console.log("Remove User from Blacklist failed: ", e); | ||
throw e; // Rethrow the error to handle it at the caller's level if needed | ||
} | ||
} | ||
|
||
module.exports = { removeBlacklist }; |
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