Skip to content
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

Edit roles page with admin privileges #330

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

kyle1373
Copy link
Member

(TO BE FILLED IN LATER)

@kyle1373
Copy link
Member Author

WIll fix the tests in the future

@@ -18,8 +18,8 @@ module.exports = [
{
type: 'postgres',
url: process.env.DATABASE_URL,
ssl: sslConfig.ssl,
extra: sslConfig.extra,
ssl: prodSSLConfig.ssl,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we changing this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally there for me personally when connecting with the dev DB. Before I finish this PR I plan on going ahead and reverting this file back. I use npm instead of docker

Comment on lines 73 to 81
handleTabs = () => {
switch (this.state.role) {
case 'admin':
return AdminTabs;
case 'officer':
return OfficerTabs;
default:
return InducteeTabs;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
handleTabs = () => {
switch (this.state.role) {
case 'admin':
return AdminTabs;
case 'officer':
return OfficerTabs;
default:
return InducteeTabs;
}
getTabsByRole = (role: string) => {
switch (role) {
case 'admin':
return AdminTabs;
case 'officer':
return OfficerTabs;
default:
return InducteeTabs;
}

easier to unit test

@@ -11,6 +11,7 @@ export const EVENT_EDIT = '/events/:eventId/edit';
export const EVENT_DETAILS = '/events/:id';
export const EVENT_CREATION = '/events?create=true';
export const TEST = '/test';
export const EDIT_ROLES = '/editroles';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const EDIT_ROLES = '/editroles';
export const EDIT_ROLES = '/roles';

in general routes don't have verbs

},
];

const ComponentToRender = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's been a while, but can't we just return the function instead of naming it ComponentToRender?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check this out more in detail and will follow up. I believe initially I had some issues with referencing the types from the MultipleAppUserResponse imports when just returning the function but worked when putting it under a component. Again, I'll look more deep into this.

};

function MemberTable(): JSX.Element {
const { data, isLoading, error, isError } = useRequest<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we push all the useRequest calls up to the page level component, then pass in the responses down to the table as a prop? makes things easier to read

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight yeah this is a better change. I remember writing this when I was first learning react. Good catch

role: newRole,
});
} catch (error) {}
window.location.reload();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't be refreshing the window from a react component, what are we trying to do here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a temporary fix for testing. I was trying to figure out a way to make it so the edited roles we submit upon popup show up on the table, since the rows themselves are only fetched once instead of updated automatically. I'm still trying to figure out a solution for this, so if you have any suggestions I'd greatly appreciate them. The rows aren't state variables either which makes it a bit harder for me to figure out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EditRolesButton can take in a callback from the parent component that sets the state of the parent component

lastName?: string;
}

class EditRolesButton extends React.Component<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just make this a functional component? Do we use class components anywhere else in the codebase? (sorry it's been a while)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use a mix of class and functional components in the codebase I believe. In this case it's fine for it to be a functional component. I'll go ahead and make that change accordingly.

Comment on lines +113 to +142
<Button
onClick={() => this.updateUserRole('guest')}
color='primary'
>
Guest
</Button>
<Button
onClick={() => this.updateUserRole('inductee')}
color='primary'
>
Inductee
</Button>
<Button
onClick={() => this.updateUserRole('member')}
color='primary'
>
Member
</Button>
<Button
onClick={() => this.updateUserRole('officer')}
color='primary'
>
Officer
</Button>
<Button
onClick={() => this.updateUserRole('admin')}
color='primary'
>
Administrator
</Button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a small thing, but you can also do the following

const roles = ['Admin', 'Officer',...];
return roles.map(role => {
    <Button 
        onClick={() => this.updateUserRole(role)}
        color='primary'
    >
        {role.toLowerCase()}
    </Button>
})

Comment on lines +69 to +78
handleEditRolePopup() {
this.setState({
isPopupOpen: true,
});
}
handleEditRoleClose() {
this.setState({
isPopupOpen: false,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe sth like the below? probably don't need 2 functions

Suggested change
handleEditRolePopup() {
this.setState({
isPopupOpen: true,
});
}
handleEditRoleClose() {
this.setState({
isPopupOpen: false,
});
}
setShowPopup(shouldShowPopup bool) {
this.setState({
isPopupOpen: shouldShowPopup,
});
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would need to do some refactoring but yeah it does shorten it up a bit. I'll also implement this.

firstName: string;
lastName: string;
}
interface INITIAL_STATES {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This INITIAL_STATES pattern is pretty old (i think pre functional components?); I remember writing stuff like this when I was first learning react 4 years ago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants