Skip to content

Commit

Permalink
Remove Deprecated Delegate edit page (#9103)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljames-dj authored Apr 1, 2024
1 parent b4fa9e7 commit 61fdecf
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 346 deletions.
53 changes: 0 additions & 53 deletions app/controllers/api/v0/user_roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,6 @@ def index_for_group_type
render json: roles
end

private def end_delegate_role_for_user(user)
if user.delegate_status.present?
remove_pending_wca_id_claims(user)
user.update!(delegate_status: '', region_id: '', location: '')
send_role_change_notification(user)
end
end

private def end_role_for_user_in_group_with_status(group, status)
if group.group_type == UserGroup.group_types[:delegate_regions]
role_to_end = group.lead_role
Expand Down Expand Up @@ -311,44 +303,11 @@ def create
}
end

def show
user_id = params.require(:userId)

user = User.find(user_id)
render json: {
roleData: {
delegateStatus: user.delegate_status,
regionId: user.region_id,
location: user.location,
},
regions: UserGroup.delegate_region_groups,
}
end

# update method is written in a way that at a time, only one parameter can be changed. If multiple
# values needs to be changed, then they need to be sent as separate APIs from the client.
def update
id = params.require(:id)

if id == UserRole::DELEGATE_ROLE_ID
# This is an exception because we are editing more than a value. But this code is anyway
# temporary, once we are done with migration, this code will be removed.
user_id = params.require(:userId)
delegate_status = params.require(:delegateStatus)
region_id = params.require(:regionId)
location = params.require(:location)

return head :unauthorized unless current_user.has_permission?(:can_edit_groups, region_id)

user = User.find(user_id)
user.update!(delegate_status: delegate_status, region_id: region_id, location: location)
send_role_change_notification(user)

return render json: {
success: true,
}
end

if id.starts_with?('delegate-')
# This tempoarily supports the non-migrated Delegate changes from the new UI.
user_id = id.split('delegate-').last
Expand Down Expand Up @@ -429,18 +388,6 @@ def update
def destroy
id = params.require(:id)

if id == UserRole::DELEGATE_ROLE_ID
user_id = params.require(:userId)
user = User.find(user_id)

return head :unauthorized unless current_user.has_permission?(:can_edit_groups, user.region_id)

end_delegate_role_for_user(user)
return render json: {
success: true,
}
end

if id.starts_with?('delegate-')
user_id = id.split('delegate-').last
user = User.find(user_id)
Expand Down
2 changes: 0 additions & 2 deletions app/models/user_role.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class UserRole < ApplicationRecord
DELEGATE_ROLE_ID = "dummyRoleId"

belongs_to :user
belongs_to :group, class_name: "UserGroup"
belongs_to :metadata, polymorphic: true, optional: true
Expand Down
4 changes: 0 additions & 4 deletions app/views/users/role.html.erb

This file was deleted.

16 changes: 2 additions & 14 deletions app/webpacker/components/RolesTab/ActiveRoles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function hyperlink(role) {
].includes(role.metadata.status)) {
return panelUrls.board.regionsManager;
}
return null;
return panelUrls.seniorDelegate.regions;
}
if (role.group.group_type === groupTypes.teams_committees) {
return `${teamUrl(role.group.id.split('_').pop())}/edit`;
Expand All @@ -25,17 +25,7 @@ function hyperlink(role) {
return null;
}

function isHyperlinkableRole(role) {
if (role.group.group_type === groupTypes.delegate_regions) {
return [
delegateRegionsStatus.senior_delegate,
delegateRegionsStatus.regional_delegate,
].includes(role.metadata.status);
}
return [groupTypes.teams_committees, groupTypes.translators].includes(role.group.group_type);
}

export default function ActiveRoles({ activeRoles, setOpen }) {
export default function ActiveRoles({ activeRoles }) {
const { loggedInUserPermissions, loading } = useLoggedInUserPermissions();
if (loading) {
return <Loading />;
Expand All @@ -57,8 +47,6 @@ export default function ActiveRoles({ activeRoles, setOpen }) {
name="edit"
size="large"
link
onClick={isHyperlinkableRole(role) ? null : () => setOpen(true)}
disabled={!loggedInUserPermissions.canEditRole(role)}
/>
</List.Content>
<List.Content>
Expand Down
84 changes: 0 additions & 84 deletions app/webpacker/components/RolesTab/DelegateForm.jsx

This file was deleted.

118 changes: 0 additions & 118 deletions app/webpacker/components/RolesTab/RoleForm.jsx

This file was deleted.

27 changes: 1 addition & 26 deletions app/webpacker/components/RolesTab/index.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from 'react';
import { Modal } from 'semantic-ui-react';
import useLoadedData from '../../lib/hooks/useLoadedData';
import { apiV0Urls } from '../../lib/requests/routes.js.erb';
import Errored from '../Requests/Errored';
import Loading from '../Requests/Loading';
import RoleForm from './RoleForm';
import ActiveRoles from './ActiveRoles';
import PastRoles from './PastRoles';

Expand All @@ -15,7 +13,6 @@ export default function RolesTab({ userId }) {
data: activeRoles,
loading: activeRolesLoading,
error: activeRolesError,
sync: activeRolesSync,
} = useLoadedData(apiV0Urls.userRoles.listOfUser(
userId,
sortParams,
Expand All @@ -25,44 +22,22 @@ export default function RolesTab({ userId }) {
data: pastRoles,
loading: pastRolesLoading,
error: pastRolesError,
sync: pastRolesSync,
} = useLoadedData(apiV0Urls.userRoles.listOfUser(
userId,
sortParams,
{ isActive: false, isGroupHidden: false },
));

const [open, setOpen] = React.useState(false);

const hasNoRoles = activeRoles?.length === 0 && pastRoles?.length === 0;

if (activeRolesLoading || pastRolesLoading) return <Loading />;
if (activeRolesError || pastRolesError) return <Errored />;

return (
<>
{activeRoles?.length > 0 && (<ActiveRoles activeRoles={activeRoles} setOpen={setOpen} />)}
{activeRoles?.length > 0 && (<ActiveRoles activeRoles={activeRoles} />)}
{pastRoles?.length > 0 && (<PastRoles pastRoles={pastRoles} />)}
{hasNoRoles && <p>No Roles...</p>}

<Modal
size="fullscreen"
onClose={() => {
setOpen(false);
activeRolesSync();
pastRolesSync();
window.location.reload(); // TODO: This is a hack to force the page to reload after
// closing the modal, so that avatar tab will be visible. A common use case of a
// Senior Delegate is that after creating a new delegate, they will want to crop the
// thumbnail. But the avatar tab is not visible until the page is reloaded because that
// part of code is still in erb. This can be fixed while migrating completely to React.
}}
open={open}
>
<Modal.Content>
<RoleForm userId={userId} />
</Modal.Content>
</Modal>
</>
);
}
Loading

0 comments on commit 61fdecf

Please sign in to comment.