Skip to content

Commit

Permalink
Merge pull request #2605 from decentdao/2582-cleanup
Browse files Browse the repository at this point in the history
Role details/edit pages cleanup
  • Loading branch information
mudrila authored Dec 6, 2024
2 parents 91591c0 + 9f6b415 commit e18755b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 33 deletions.
36 changes: 25 additions & 11 deletions src/components/Roles/RoleDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Badge, Box, Flex, Grid, GridItem, Icon, Text } from '@chakra-ui/react';
import { CheckSquare, List, User } from '@phosphor-icons/react';
import { Badge, Box, Button, Flex, Grid, GridItem, Icon, Text } from '@chakra-ui/react';
import { ArrowLeft, CheckSquare, List, User } from '@phosphor-icons/react';
import { RefObject, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -135,19 +135,33 @@ export default function RolesDetails({
</Box>
),
gap: 0,
children: t('editRoles'),
onClick: () => navigate(DAO_ROUTES.rolesEdit.relative(addressPrefix, safe.address)),
children: t('editRole'),
onClick: () => {
navigate(
DAO_ROUTES.rolesEditDetails.relative(addressPrefix, safe.address, roleHat.id),
);
},
}
: undefined
}
/>
<Text
textStyle="heading-large"
color="white-0"
my="1rem"
>
{roleHat.name}
</Text>
<Flex justifyContent="space-between">
<Text
textStyle="heading-large"
color="white-0"
my="1rem"
>
{roleHat.name}
</Text>
<Button
variant="tertiary"
width="min-content"
color="lilac-0"
pr={2}
leftIcon={<ArrowLeft />}
onClick={() => navigate(DAO_ROUTES.roles.relative(addressPrefix, safe.address))}
/>
</Flex>
<Grid
gridTemplateAreas={`
"mLabel mValue"
Expand Down
36 changes: 15 additions & 21 deletions src/components/Roles/forms/RoleFormMember.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import { useTranslation } from 'react-i18next';
import { DecentHourGlass } from '../../../assets/theme/custom/icons/DecentHourGlass';
import { DETAILS_BOX_SHADOW } from '../../../constants/common';
import useAddress from '../../../hooks/utils/useAddress';
import { useGetAccountName } from '../../../hooks/utils/useGetAccountName';
import { RoleFormValues } from '../../../types/roles';
import DraggableDrawer from '../../ui/containers/DraggableDrawer';
import { AddressInput } from '../../ui/forms/EthAddressInput';
import LabelWrapper from '../../ui/forms/LabelWrapper';
import { InputComponent } from '../../ui/forms/InputComponent';
import { ModalBase } from '../../ui/modals/ModalBase';
import RoleFormTerms from './RoleFormTerms';

Expand All @@ -38,14 +36,13 @@ function RoleMemberWearerInput() {
const { address: resolvedWearerAddress, isValid: isValidWearerAddress } =
useAddress(roleWearerString);

const { setFieldValue, values } = useFormikContext<RoleFormValues>();
const { setFieldValue } = useFormikContext<RoleFormValues>();
useEffect(() => {
if (isValidWearerAddress) {
setFieldValue('roleEditing.resolvedWearer', resolvedWearerAddress);
}
}, [isValidWearerAddress, resolvedWearerAddress, setFieldValue]);

const { displayName } = useGetAccountName(values.roleEditing?.resolvedWearer, false);
return (
<FormControl>
<Field name="roleEditing.wearer">
Expand All @@ -58,24 +55,21 @@ function RoleMemberWearerInput() {
form: FormikProps<RoleFormValues>;
meta: FieldMetaProps<string>;
}) => (
<LabelWrapper
<InputComponent
label={t('member')}
errorMessage={meta.touched && meta.error ? meta.error : undefined}
isRequired
labelColor="neutral-7"
>
<AddressInput
value={displayName ?? field.value}
onBlur={() => {
setFieldTouched('roleEditing.wearer', true);
}}
onChange={e => {
const inputWearer = e.target.value;
setRoleWearerString(inputWearer);
setFieldValue('roleEditing.wearer', inputWearer);
}}
/>
</LabelWrapper>
value={field.value}
errorMessage={meta.touched && meta.error ? meta.error : undefined}
onBlur={() => {
setFieldTouched('roleEditing.wearer', true);
}}
onChange={e => {
const inputWearer = e.target.value;
setRoleWearerString(inputWearer);
setFieldValue('roleEditing.wearer', inputWearer);
}}
testId="role-wearer"
/>
)}
</Field>
</FormControl>
Expand Down
11 changes: 11 additions & 0 deletions src/components/Roles/forms/RoleFormTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button, Flex, Tab, TabList, TabPanel, TabPanels, Tabs } from '@chakra-ui/react';
import { ArrowLeft } from '@phosphor-icons/react';
import { useFormikContext } from 'formik';
import { useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -58,6 +59,16 @@ export function RoleFormTabs({

return (
<>
<Flex justifyContent="flex-end">
<Button
variant="tertiary"
width="min-content"
color="lilac-0"
pr={2}
leftIcon={<ArrowLeft />}
onClick={() => navigate(DAO_ROUTES.rolesEdit.relative(addressPrefix, safe.address))}
/>
</Flex>
<Tabs variant="twoTone">
<TabList>
<Tab>{t('roleInfo')}</Tab>
Expand Down
35 changes: 34 additions & 1 deletion src/pages/dao/roles/edit/SafeRolesEditPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as amplitude from '@amplitude/analytics-browser';
import { Box, Button, Flex, Show } from '@chakra-ui/react';
import { Box, Button, Flex, Hide, Show } from '@chakra-ui/react';
import { Plus } from '@phosphor-icons/react';
import { useFormikContext } from 'formik';
import { useEffect, useState } from 'react';
Expand All @@ -9,7 +9,10 @@ import { Hex, toHex } from 'viem';
import { RoleCardEdit } from '../../../../components/Roles/RoleCard';
import { RoleCardLoading } from '../../../../components/Roles/RolePageCard';
import { RolesEditTable } from '../../../../components/Roles/RolesTable';
import DraggableDrawer from '../../../../components/ui/containers/DraggableDrawer';
import NoDataCard from '../../../../components/ui/containers/NoDataCard';
import { ModalBase } from '../../../../components/ui/modals/ModalBase';
import { UnsavedChangesWarningContent } from '../../../../components/ui/modals/UnsavedChangesWarningContent';
import PageHeader from '../../../../components/ui/page/Header/PageHeader';
import { DAO_ROUTES } from '../../../../constants/routes';
import { getRandomBytes } from '../../../../helpers';
Expand Down Expand Up @@ -51,6 +54,36 @@ export function SafeRolesEditPage() {

return (
<>
{blocker.state === 'blocked' && (
<>
<Hide above="md">
<DraggableDrawer
isOpen
onClose={() => {}}
onOpen={() => {}}
headerContent={null}
initialHeight="23rem"
closeOnOverlayClick={false}
>
<UnsavedChangesWarningContent
onDiscard={blocker.proceed}
onKeepEditing={blocker.reset}
/>
</DraggableDrawer>
</Hide>
<Hide below="md">
<ModalBase
isOpen
onClose={() => {}}
>
<UnsavedChangesWarningContent
onDiscard={blocker.proceed}
onKeepEditing={blocker.reset}
/>
</ModalBase>
</Hide>
</>
)}
<Box>
<PageHeader
title={t('roles')}
Expand Down

0 comments on commit e18755b

Please sign in to comment.