resolved permission error from permissions coming back as string

This commit is contained in:
Carter 2024-11-19 17:32:37 -06:00
parent cf4e3fbe1f
commit aa56f05c25
4 changed files with 43 additions and 28 deletions

View file

@ -159,7 +159,7 @@ export default function TeamActions(props: Props) {
label={label}
isDialogOpen={openState.removeSelf}
closeDialogCallback={(removeSelf: boolean) => {
console.log(removeSelf)
// console.log(removeSelf)
if (removeSelf) refreshCallback()
setOpenState({ ...openState, removeSelf: false })
}}
@ -168,7 +168,6 @@ export default function TeamActions(props: Props) {
);
};
// console.log(permissions)
const canWrite = permissions.includes(pond.Permission.PERMISSION_WRITE);
return (
<React.Fragment>

View file

@ -28,10 +28,10 @@ import PrevIcon from "@mui/icons-material/NavigateBefore";
import LastIcon from "@mui/icons-material/SkipNext";
import FirstIcon from "@mui/icons-material/SkipPrevious";
import TeamSettings from "./TeamSettings";
import { Add, AddBox, AddOutlined } from "@mui/icons-material";
import { AddBox } from "@mui/icons-material";
import { cloneDeep } from "lodash";
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
import { makeStyles, styled } from "@mui/styles";
import { makeStyles } from "@mui/styles";
import TeamActions from "./TeamActions";
const useStyles = makeStyles((theme: Theme) => ({
@ -76,9 +76,7 @@ const limits = [
}
];
interface Props {}
export default function TeamList(props: Props) {
export default function TeamList() {
const classes = useStyles();
const [teams, setTeams] = useState<pond.Team[]>([]);
const teamAPI = useTeamAPI();
@ -98,22 +96,6 @@ export default function TeamList(props: Props) {
const [userId, setUserId] = useState<string | undefined>(undefined);
const [isUser, setIsUser] = useState<boolean>(true);
// const ColorAdd = styled(Add)((theme: Theme) => ({
// color: theme.palette.getContrastText(theme.palette.primary.main),
// backgroundColor: theme.palette.primary.main,
// marginTop: 'auto',
// marginBottom: 'auto',
// borderRadius: '4px',
// '&:hover': {
// backgroundColor: theme.palette.primary.light,
// cursor: 'pointer',
// },
// '&:disabled': {
// backgroundColor: 'rgba(0,0,0,0)',
// color: theme.palette.getContrastText(theme.palette.primary.main),
// },
// }));
useEffect(() => {
if (as.includes("auth0")) setAsUser(as);
}, [as]);
@ -130,6 +112,13 @@ export default function TeamList(props: Props) {
setIsUser(userId === asUser);
}, [userId, asUser]);
// Convert string array to valid Permission[] array
// const convertToPermissions = (permissions: any[]): pond.Permission[] => {
// return permissions
// .map(p => p as any as pond.Permission) // Type assertion to treat strings as Permission
// .filter(p => Object.entries(pond.Permission).includes(p)); // Filter to ensure valid Permission values
// };
const loadTeams = useCallback(() => {
setLoading(true);
let newTeamPerms: pond.Permission[][] = [];
@ -145,6 +134,16 @@ export default function TeamList(props: Props) {
userAPI
.getUser(u, teamScope(team.settings?.key))
.then(resp => {
// let permissions: pond.Permission[] = resp.permissions.map(perm => pond.Permission[perm as unknown as keyof typeof pond.Permission]);
// console.log(resp.permissions)
// console.log(typeof(resp.permissions))
resp.permissions.forEach(p => {
// console.log('Value:', p, 'Type:', typeof p);
});
// permissions.forEach(p => {
// console.log('Value:', p, 'Type:', typeof p);
// });
// console.log('Expected Value:', pond.Permission.PERMISSION_WRITE, 'Type:', typeof pond.Permission.PERMISSION_WRITE);
newTeamPerms[index] = resp.permissions;
newTeamPrefs[index] = resp.preferences;
})
@ -183,7 +182,7 @@ export default function TeamList(props: Props) {
<ListItemAvatar>
<Avatar
onClick={() => {
if (team.settings) history("teams/" + team.settings.key);
if (team.settings) history(team.settings.key);
}}
src={team.settings?.avatar}
alt=""
@ -195,7 +194,7 @@ export default function TeamList(props: Props) {
<div
className={classes.clickable}
onClick={() => {
if (team.settings) history("teams/" + team.settings.key);
if (team.settings) history(team.settings.key);
}}>
{team.settings?.name}
</div>
@ -219,7 +218,6 @@ export default function TeamList(props: Props) {
if (preferences) {
let newTeamPrefs = cloneDeep(teamPrefs);
newTeamPrefs[index].notify = !newTeamPrefs[index].notify;
console.log(newTeamPrefs[index]);
teamAPI
.updatePreferences(
Team.create(team).key(),
@ -227,7 +225,7 @@ export default function TeamList(props: Props) {
getContextKeys(),
getContextTypes()
)
.then(resp => {
.then(() => {
setTeamPrefs(newTeamPrefs);
});
// setTeamPrefs(newTeamPrefs)