Skip to content

Commit

Permalink
Merge branch 'issue/2583-remove-roles-drawer' into issue/2583-move-ro…
Browse files Browse the repository at this point in the history
…le-details-to-page
  • Loading branch information
Da-Colon authored Dec 5, 2024
2 parents 7d2e56f + 0a8c28b commit ea980be
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions src/pages/dao/roles/edit/SafeRolesEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { analyticsEvents } from '../../../../insights/analyticsEvents';
import { useNetworkConfig } from '../../../../providers/NetworkConfig/NetworkConfigProvider';
import { useDaoInfoStore } from '../../../../store/daoInfo/useDaoInfoStore';
import { useRolesStore } from '../../../../store/roles/useRolesStore';
import { EditBadgeStatus, RoleFormValues } from '../../../../types/roles';
import { RoleFormValues } from '../../../../types/roles';

export function SafeRolesEditPage() {
useEffect(() => {
Expand All @@ -29,35 +29,12 @@ export function SafeRolesEditPage() {
const { safe } = useDaoInfoStore();
const { addressPrefix } = useNetworkConfig();

const { values, setFieldValue, touched } = useFormikContext<RoleFormValues>();
const { values, setFieldValue } = useFormikContext<RoleFormValues>();

const { hatsTree } = useRolesStore();

const navigate = useNavigate();

function generateRoleProposalTitle({ formValues }: { formValues: RoleFormValues }) {
const filteredHats = formValues.hats.filter(hat => !!hat.editedRole);
const addedHatsCount = filteredHats.filter(
hat => hat.editedRole!.status === EditBadgeStatus.New,
).length;
const updatedHatsCount = filteredHats.filter(
hat => hat.editedRole!.status === EditBadgeStatus.Updated,
).length;
const removedHatsCount = filteredHats.filter(
hat => hat.editedRole!.status === EditBadgeStatus.Removed,
).length;

const addedHatsText = addedHatsCount > 0 ? t('addedHats', { count: addedHatsCount }) : '';

const updatedHatsText =
updatedHatsCount > 0 ? t('updatedHats', { count: updatedHatsCount }) : '';

const removedHatsText =
removedHatsCount > 0 ? t('removedHats', { count: removedHatsCount }) : '';

return [addedHatsText, updatedHatsText, removedHatsText].filter(Boolean).join('. ');
}

const [hasEditedRoles, setHasEditedRoles] = useState(false);

const blocker = useNavigationBlocker({ roleEditPageNavigationBlockerParams: { hasEditedRoles } });
Expand Down Expand Up @@ -155,12 +132,6 @@ export function SafeRolesEditPage() {
</Button>
<Button
onClick={() => {
if (!touched.proposalMetadata?.title || !values.proposalMetadata.title) {
setFieldValue(
'proposalMetadata.title',
generateRoleProposalTitle({ formValues: values }),
);
}
if (blocker.reset) {
blocker.reset();
}
Expand Down

0 comments on commit ea980be

Please sign in to comment.