Skip to content

Commit

Permalink
Merge pull request #2592 from decentdao/2526-edit-role-updates
Browse files Browse the repository at this point in the history
`[PRD]` | Edit Role UI/UX updates
  • Loading branch information
mudrila authored Dec 5, 2024
2 parents f3d4743 + 8f7259f commit e51e012
Show file tree
Hide file tree
Showing 24 changed files with 759 additions and 840 deletions.
15 changes: 15 additions & 0 deletions src/assets/theme/components/button/button.variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ const tertiary = defineStyle({
_focus: {},
});

const danger = defineStyle({
border: '1px solid',
borderColor: 'red-1',
color: 'red-1',
_hover: {
borderColor: 'red-0',
color: 'red-0',
},
_active: {
borderColor: 'red-0',
color: 'red-0',
},
});

const stepper = defineStyle({
border: '1px solid',
borderColor: 'neutral-3',
Expand All @@ -98,6 +112,7 @@ const buttonVariants = {
secondary,
tertiary,
stepper,
danger,
};

export default buttonVariants;
18 changes: 4 additions & 14 deletions src/components/ProposalBuilder/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Flex, Grid, GridItem, Icon, Text } from '@chakra-ui/react';
import { ArrowLeft, SquaresFour } from '@phosphor-icons/react';
import { Box, Flex, Grid, GridItem, Text } from '@chakra-ui/react';
import { ArrowLeft } from '@phosphor-icons/react';
import { Formik, FormikProps } from 'formik';
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -265,21 +265,11 @@ export function ProposalBuilder({
gap="0.5rem"
>
<Flex
mt={4}
mt={6}
mb={2}
alignItems="center"
>
<Icon
as={SquaresFour}
w="1.5rem"
h="1.5rem"
/>
<Text
textStyle="heading-small"
ml={2}
>
{t('actions', { ns: 'actions' })}
</Text>
<Text ml={2}>{t('actions', { ns: 'actions' })}</Text>
</Flex>
{actions.map((action, index) => {
return (
Expand Down
238 changes: 238 additions & 0 deletions src/components/Roles/RoleDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
import { Badge, Box, Flex, Grid, GridItem, Icon, Text } from '@chakra-ui/react';
import { CheckSquare, List, User } from '@phosphor-icons/react';
import { RefObject, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import PencilWithLineIcon from '../../assets/theme/custom/icons/PencilWithLineIcon';
import { DAO_ROUTES } from '../../constants/routes';
import useAddress from '../../hooks/utils/useAddress';
import useAvatar from '../../hooks/utils/useAvatar';
import { useCanUserCreateProposal } from '../../hooks/utils/useCanUserSubmitProposal';
import { useCopyText } from '../../hooks/utils/useCopyText';
import { useGetAccountName } from '../../hooks/utils/useGetAccountName';
import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigProvider';
import { useDaoInfoStore } from '../../store/daoInfo/useDaoInfoStore';
import {
paymentSorterByActiveStatus,
paymentSorterByStartDate,
paymentSorterByWithdrawAmount,
} from '../../store/roles/rolesStoreUtils';
import {
RoleDetailsDrawerEditingRoleHatProp,
RoleDetailsDrawerRoleHatProp,
} from '../../types/roles';
import { BarLoader } from '../ui/loaders/BarLoader';
import ModalTooltip from '../ui/modals/ModalTooltip';
import Avatar from '../ui/page/Header/Avatar';
import PageHeader from '../ui/page/Header/PageHeader';
import Markdown from '../ui/proposal/Markdown';
import Divider from '../ui/utils/Divider';
import RoleDetailsTabs from './RoleDetailsTabs';

export function RoleProposalPermissionBadge({
containerRef,
}: {
containerRef: RefObject<HTMLDivElement>;
}) {
const { t } = useTranslation('roles');
return (
<ModalTooltip
containerRef={containerRef}
label={t('permissionsProposalsTooltip')}
>
<Badge
color="celery-0"
bgColor="celery--6"
textTransform="unset"
fontSize="1rem"
lineHeight="1.5rem"
fontWeight="normal"
borderRadius="0.25rem"
px="0.5rem"
>
{t('permissionsProposals')}
</Badge>
</ModalTooltip>
);
}
function RoleAndDescriptionLabel({ label, icon }: { label: string; icon: React.ElementType }) {
return (
<Flex
gap="0.5rem"
alignItems="center"
>
<Icon as={icon} />
<Text
textStyle="labels-large"
color="neutral-7"
>
{label}
</Text>
</Flex>
);
}

export default function RolesDetails({
roleHat,
}: {
roleHat: RoleDetailsDrawerRoleHatProp | RoleDetailsDrawerEditingRoleHatProp;
}) {
const { safe } = useDaoInfoStore();
const navigate = useNavigate();
const { addressPrefix } = useNetworkConfig();
const permissionsContainerRef = useRef<HTMLDivElement>(null);

const roleHatWearer = 'wearer' in roleHat ? roleHat.wearer : roleHat.wearerAddress;

const { address: roleHatWearerAddress, isLoading: loadingRoleHatWearerAddress } =
useAddress(roleHatWearer);

const { displayName } = useGetAccountName(roleHatWearerAddress);

const { t } = useTranslation(['roles']);
const avatarURL = useAvatar(roleHatWearer);

const sortedPayments = useMemo(
() =>
roleHat.payments
? [...roleHat.payments]
.sort(paymentSorterByWithdrawAmount)
.sort(paymentSorterByStartDate)
.sort(paymentSorterByActiveStatus)
: [],
[roleHat.payments],
);

const { canUserCreateProposal } = useCanUserCreateProposal();
const copyToClipboard = useCopyText();

if (!safe?.address) return null;

return (
<>
<PageHeader
breadcrumbs={[
{
terminus: t('roles'),
path: DAO_ROUTES.roles.relative(addressPrefix, safe.address),
},
{
terminus: roleHat.name,
path: '',
},
]}
buttonProps={
canUserCreateProposal
? {
variant: 'secondary',
size: 'sm',
leftIcon: (
<Box mr="-0.25rem">
<PencilWithLineIcon
w="1rem"
h="1rem"
/>
</Box>
),
gap: 0,
children: t('editRoles'),
onClick: () => navigate(DAO_ROUTES.rolesEdit.relative(addressPrefix, safe.address)),
}
: undefined
}
/>
<Text
textStyle="heading-large"
color="white-0"
my="1rem"
>
{roleHat.name}
</Text>
<Grid
gridTemplateAreas={`
"mLabel mValue"
"dLabel dValue"
"pLabel pValue"
`}
gridRowGap="1rem"
gridColumnGap="2rem"
alignItems="center"
>
<GridItem area="mLabel">
<RoleAndDescriptionLabel
label={t('member')}
icon={User}
/>
</GridItem>
<GridItem area="dLabel">
<RoleAndDescriptionLabel
label={t('description')}
icon={List}
/>
</GridItem>
<GridItem area="pLabel">
{roleHat.canCreateProposals && (
<RoleAndDescriptionLabel
label={t('permissions')}
icon={CheckSquare}
/>
)}
</GridItem>
<GridItem area="mValue">
<Flex
alignItems="center"
gap="0.5rem"
p="0.25rem 0.5rem"
ml="-0.75rem"
rounded="1rem"
bg="neutral-3"
color="lilac-0"
_hover={{
color: 'white-0',
bg: 'neutral-4',
}}
cursor="pointer"
maxW="fit-content"
onClick={() => copyToClipboard(roleHatWearerAddress)}
>
{loadingRoleHatWearerAddress || !roleHatWearerAddress ? (
<BarLoader />
) : (
<Avatar
size="icon"
address={roleHatWearerAddress}
url={avatarURL}
/>
)}
<Text>{displayName}</Text>
</Flex>
</GridItem>
<GridItem area="dValue">
<Markdown
content={roleHat.description}
collapsedLines={100}
/>
</GridItem>
<GridItem
area="pValue"
ref={permissionsContainerRef}
>
{roleHat.canCreateProposals && (
<RoleProposalPermissionBadge containerRef={permissionsContainerRef} />
)}
</GridItem>
</Grid>
<Divider
variant="darker"
my={4}
/>
<RoleDetailsTabs
hatId={roleHat.id}
roleHatSmartAccountAddress={roleHat.smartAddress}
roleTerms={roleHat.roleTerms}
roleHatWearerAddress={roleHatWearerAddress}
sortedPayments={sortedPayments}
/>
</>
);
}
25 changes: 14 additions & 11 deletions src/components/Roles/RoleDetailsTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ function RolesDetailsPayments({
variant="darker"
my={4}
/>
{sortedPayments.map((payment, index) => (
<RolePaymentDetails
key={index}
payment={payment}
roleHatSmartAccountAddress={roleHatSmartAccountAddress}
roleHatId={roleHatId}
roleTerms={roleTerms}
roleHatWearerAddress={roleHatWearerAddress}
showWithdraw
/>
))}
{sortedPayments.map(payment => {
const thisPaymentIndex = payments?.findIndex(p => p.streamId === payment.streamId);
return (
<RolePaymentDetails
key={thisPaymentIndex}
payment={payment}
roleHatSmartAccountAddress={roleHatSmartAccountAddress}
roleHatId={roleHatId}
roleTerms={roleTerms}
roleHatWearerAddress={roleHatWearerAddress}
showWithdraw
/>
);
})}
</>
);
}
Expand Down
Loading

0 comments on commit e51e012

Please sign in to comment.