Skip to content

Commit

Permalink
Merge pull request #2590 from decentdao/issue/2583-remove-roles-drawer
Browse files Browse the repository at this point in the history
`[PRD | Issue #2582]` Move Role Form to own page
  • Loading branch information
mudrila authored Dec 5, 2024
2 parents a4ad29e + 0a8c28b commit 7b30f9c
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 478 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;
9 changes: 7 additions & 2 deletions src/components/Roles/forms/RoleFormInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default function RoleFormInfo() {
return (
<>
<Box
px={{ base: '1rem', md: 0 }}
py="1rem"
p="1.5rem"
bg="neutral-2"
boxShadow={{
base: DETAILS_BOX_SHADOW,
Expand Down Expand Up @@ -108,12 +107,18 @@ export default function RoleFormInfo() {
<Field name="roleEditing.canCreateProposals">
{() => (
<Flex
mt={6}
justifyContent="space-between"
alignItems="center"
padding={4}
borderRadius={8}
border="1px solid"
borderColor="neutral-3"
bg="neutral-2"
boxShadow={{
base: DETAILS_BOX_SHADOW,
md: 'unset',
}}
>
<Text>{t('canCreateProposals')}</Text>
<Switch
Expand Down
4 changes: 2 additions & 2 deletions src/components/Roles/forms/RoleFormMember.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ function RoleFormMemberTermToggle() {
padding="1.5rem"
border="1px solid"
borderColor="neutral-3"
bg="neutral-2"
borderRadius="0.25rem"
mt="1.5rem"
>
Expand Down Expand Up @@ -318,8 +319,7 @@ export function RoleFormMember() {
return (
<Box>
<Box
px={{ base: '1rem', md: 0 }}
py="1rem"
p="1.5rem"
bg="neutral-2"
boxShadow={{
base: DETAILS_BOX_SHADOW,
Expand Down
9 changes: 4 additions & 5 deletions src/components/Roles/forms/RoleFormPaymentStream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { addDays, addMinutes } from 'date-fns';
import { Field, FieldProps, FormikErrors, useFormikContext } from 'formik';
import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { CARD_SHADOW, isDevMode } from '../../../constants/common';
import { DETAILS_BOX_SHADOW, isDevMode } from '../../../constants/common';
import { useRolesStore } from '../../../store/roles/useRolesStore';
import { RoleFormValues, RoleHatFormValue } from '../../../types/roles';
import { DatePicker } from '../../ui/forms/DatePicker';
Expand Down Expand Up @@ -171,15 +171,14 @@ export function RoleFormPaymentStream({ formIndex }: { formIndex: number }) {
return (
<>
<Box
px={{ base: '1rem', md: 0 }}
py="1rem"
p="1.5rem"
mt={4}
bg="neutral-2"
boxShadow={{
base: CARD_SHADOW,
base: DETAILS_BOX_SHADOW,
md: 'unset',
}}
borderRadius="0.5rem"
position="relative"
>
<SectionTitle
title={t('asset')}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Roles/forms/RoleFormPaymentStreamTermed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ export default function RoleFormPaymentStreamTermed({ paymentIndex }: { paymentI
<Box
bg="neutral-2"
borderRadius="0.5rem"
p="1.5rem"
mt={4}
>
<ShadowedBox>
<SectionTitle
Expand Down
22 changes: 21 additions & 1 deletion src/components/Roles/forms/RoleFormPaymentStreams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ import { ModalType } from '../../ui/modals/ModalProvider';
import { useDecentModal } from '../../ui/modals/useDecentModal';
import Divider from '../../ui/utils/Divider';
import { RolePaymentDetails } from '../RolePaymentDetails';
import { RoleFormPaymentStream } from './RoleFormPaymentStream';
import RoleFormPaymentStreamTermed from './RoleFormPaymentStreamTermed';

export function RoleFormPaymentRenderer() {
const { values } = useFormikContext<RoleFormValues>();

if (values.roleEditing?.roleEditingPaymentIndex !== undefined) {
if (values.roleEditing?.isTermed) {
return (
<RoleFormPaymentStreamTermed paymentIndex={values.roleEditing.roleEditingPaymentIndex} />
);
} else {
return <RoleFormPaymentStream formIndex={values.roleEditing.roleEditingPaymentIndex} />;
}
}

return null;
}

export function RoleFormPaymentStreams() {
const { t } = useTranslation(['roles']);
Expand Down Expand Up @@ -61,6 +79,7 @@ export function RoleFormPaymentStreams() {
<Box>
{sortedPayments.length === 0 && (
<Flex
bg="neutral-2"
padding="1.5rem"
border="1px solid"
borderColor="neutral-3"
Expand Down Expand Up @@ -98,7 +117,8 @@ export function RoleFormPaymentStreams() {
>
{t('addPayment')}
</Button>
<Divider my="1rem" />
<RoleFormPaymentRenderer />
{!!sortedPayments.length && <Divider my="1rem" />}
<Box mt="0.5rem">
{sortedPayments.map(payment => {
// @note don't render if form isn't valid
Expand Down
23 changes: 2 additions & 21 deletions src/components/Roles/forms/RoleFormTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Flex, Tab, TabList, TabPanel, TabPanels, Tabs } from '@chakra-ui/react';
import { useFormikContext } from 'formik';
import { useEffect, useRef, useState } from 'react';
import { useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { Blocker, useNavigate } from 'react-router-dom';
import { Hex } from 'viem';
Expand All @@ -11,8 +11,6 @@ import { useRolesStore } from '../../../store/roles/useRolesStore';
import { EditBadgeStatus, RoleFormValues, RoleHatFormValue } from '../../../types/roles';
import RoleFormInfo from './RoleFormInfo';
import { RoleFormMember } from './RoleFormMember';
import { RoleFormPaymentStream } from './RoleFormPaymentStream';
import RoleFormPaymentStreamTermed from './RoleFormPaymentStreamTermed';
import { RoleFormPaymentStreams } from './RoleFormPaymentStreams';
import { useRoleFormEditedRole } from './useRoleFormEditedRole';

Expand Down Expand Up @@ -55,28 +53,12 @@ export function RoleFormTabs({
}
}, [setFieldValue, values.hats, values.roleEditing, hatId]);

const [tabIndex, setTabIndex] = useState(0);

const safeAddress = safe?.address;
if (!safeAddress) return null;

if (values.roleEditing?.roleEditingPaymentIndex !== undefined) {
if (values.roleEditing?.isTermed) {
return (
<RoleFormPaymentStreamTermed paymentIndex={values.roleEditing?.roleEditingPaymentIndex} />
);
} else {
return <RoleFormPaymentStream formIndex={values.roleEditing?.roleEditingPaymentIndex} />;
}
}

return (
<>
<Tabs
index={tabIndex}
onChange={setTabIndex}
variant="twoTone"
>
<Tabs variant="twoTone">
<TabList>
<Tab>{t('roleInfo')}</Tab>
<Tab>{t('member')}</Tab>
Expand Down Expand Up @@ -112,7 +94,6 @@ export function RoleFormTabs({
} else if (existingRoleHat !== undefined) {
setFieldValue(`hats.${hatIndex}`, {
...existingRoleHat,
resolvedWearer: existingRoleHat.wearerAddress,
roleTerms: existingRoleHat.roleTerms.allTerms,
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Roles/forms/RoleFormTerms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ function RoleTermExpiredTerms({
<Box
borderRadius="0.5rem"
boxShadow="layeredShadowBorder"
bg="neutral-2"
p="1.5rem"
>
<Accordion allowToggle>
<AccordionItem
Expand All @@ -238,7 +240,6 @@ function RoleTermExpiredTerms({
<AccordionButton
borderTopRadius="0.5rem"
borderBottomRadius="0.5rem"
p="1rem"
>
<Flex
alignItems="center"
Expand Down
55 changes: 55 additions & 0 deletions src/pages/dao/roles/edit/SafeRolesEditFormikPageWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as amplitude from '@amplitude/analytics-browser';
import { Formik } from 'formik';
import { useEffect, useMemo } from 'react';
import { Outlet } from 'react-router-dom';
import { useRolesSchema } from '../../../../hooks/schemas/roles/useRolesSchema';
import useCreateRoles from '../../../../hooks/utils/useCreateRoles';
import { analyticsEvents } from '../../../../insights/analyticsEvents';
import { useDaoInfoStore } from '../../../../store/daoInfo/useDaoInfoStore';
import { useRolesStore } from '../../../../store/roles/useRolesStore';
import { RoleFormValues } from '../../../../types/roles';

export default function SafeRolesEditFormikPageWrapper() {
useEffect(() => {
amplitude.track(analyticsEvents.RolesEditPageOpened);
}, []);

const { safe } = useDaoInfoStore();

const { rolesSchema } = useRolesSchema();
const { hatsTree } = useRolesStore();

const { createEditRolesProposal } = useCreateRoles();
const initialValues: RoleFormValues = useMemo(() => {
const hats = hatsTree?.roleHats || [];
return {
proposalMetadata: {
title: '',
description: '',
},
hats: hats.map(hat => ({
...hat,
resolvedWearer: hat.wearerAddress,
wearer: hat.wearerAddress,
roleTerms: hat.roleTerms.allTerms,
})),
customNonce: safe?.nextNonce || 0,
actions: [],
};
}, [hatsTree?.roleHats, safe?.nextNonce]);
return (
<Formik<RoleFormValues>
initialValues={initialValues}
enableReinitialize
validationSchema={rolesSchema}
validateOnMount
onSubmit={createEditRolesProposal}
>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<Outlet />
</form>
)}
</Formik>
);
}
Loading

0 comments on commit 7b30f9c

Please sign in to comment.