Skip to content

Commit

Permalink
fix: undo previous overview and remove permissions from modal
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-strzelec committed Dec 19, 2024
1 parent 7324522 commit d808b86
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { type FC } from 'react';
import { defineMessages } from 'react-intl';

import { formatText } from '~utils/intl.ts';
import MenuWithStatusText from '~v5/shared/MenuWithStatusText/index.ts';
import { StatusTypes } from '~v5/shared/StatusText/consts.ts';
import StatusText from '~v5/shared/StatusText/StatusText.tsx';
import UserPopover from '~v5/shared/UserPopover/UserPopover.tsx';

import { type FinalizeByPaymentCreatorInfoProps } from './types.ts';

const displayName =
'v5.common.CompletedAction.partials.PaymentBuilder.partials.FinalizeByPaymentCreatorInfo';

const MSG = defineMessages({
info: {
id: `${displayName}.info`,
defaultMessage: 'Payment creator released the payment.',
},
overview: {
id: `${displayName}.overview`,
defaultMessage: 'Overview',
},
member: {
id: `${displayName}.member`,
defaultMessage: 'Member',
},
});

const FinalizeByPaymentCreatorInfo: FC<FinalizeByPaymentCreatorInfoProps> = ({
userAdddress,
}) => {
return (
<MenuWithStatusText
statusText={
<StatusText
status={StatusTypes.Info}
textClassName="text-4 text-gray-900"
iconAlignment="top"
iconSize={16}
iconClassName="text-gray-500"
>
{formatText(MSG.info)}
</StatusText>
}
sections={[
{
key: '1',
content: (
<>
<h4 className="text-1">{formatText(MSG.overview)}</h4>
{userAdddress && (
<div className="mt-2 flex items-center justify-between gap-2">
<span className="text-sm text-gray-600">
{formatText(MSG.member)}
</span>
<div>
<UserPopover size={18} walletAddress={userAdddress || ''} />
</div>
</div>
)}
</>
),
},
]}
/>
);
};

export default FinalizeByPaymentCreatorInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface FinalizeByPaymentCreatorInfoProps {
userAdddress: string | undefined | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { type StepperItem } from '~v5/shared/Stepper/types.ts';

import ActionWithPermissionsInfo from '../ActionWithPermissionsInfo/ActionWithPermissionsInfo.tsx';
import ActionWithStakingInfo from '../ActionWithStakingInfo/ActionWithStakingInfo.tsx';
import FinalizeByPaymentCreatorInfo from '../FinalizeByPaymentCreatorInfo/FinalizeByPaymentCreatorInfo.tsx';
import FundingModal from '../FundingModal/FundingModal.tsx';
import FundingRequests from '../FundingRequests/FundingRequests.tsx';
import MotionBox from '../MotionBox/MotionBox.tsx';
Expand Down Expand Up @@ -96,6 +97,7 @@ const PaymentBuilderWidget: FC<PaymentBuilderWidgetProps> = ({ action }) => {
finalizedAt,
isStaked,
userStake,
ownerAddress,
status,
} = expenditure || {};
const { amount: stakeAmount = '' } = userStake || {};
Expand Down Expand Up @@ -453,10 +455,18 @@ const PaymentBuilderWidget: FC<PaymentBuilderWidgetProps> = ({ action }) => {
) : (
<>
{finalizedAt ? (
<ActionWithPermissionsInfo
action={finalizingActions?.items[0]}
statusText="action.executed.creator.description"
/>
<>
{finalizingActions?.items[0]?.initiatorAddress ===
ownerAddress ? (
<FinalizeByPaymentCreatorInfo
userAdddress={expenditure?.ownerAddress}
/>
) : (
<ActionWithPermissionsInfo
action={finalizingActions?.items[0]}
/>
)}
</>
) : (
<div />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ const ReleasePaymentModal: FC<ReleasePaymentModalProps> = ({
isOpen,
onClose,
onSuccess,
actionType,
...rest
}) => {
const { colony } = useColonyContext();
const { user } = useAppContext();
const releaseDecisionMethodItems = useGetReleaseDecisionMethodItems(
expenditure,
actionType,
);
const releaseDecisionMethodItems =
useGetReleaseDecisionMethodItems(expenditure);

const noDecisionMethodAvailable = releaseDecisionMethodItems.every(
({ isDisabled }) => isDisabled,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { type Action } from '~constants/actions.ts';
import { useAppContext } from '~context/AppContext/AppContext.ts';
import { DecisionMethod } from '~types/actions.ts';
import { type Expenditure } from '~types/graphql.ts';
import { formatText } from '~utils/intl.ts';
import { useCheckIfUserHasPermissions } from '~v5/common/CompletedAction/partials/PaymentBuilder/hooks.ts';

import { type DecisionMethodOption } from '../DecisionMethodSelect/types.ts';

export const useGetReleaseDecisionMethodItems = (
expenditure: Expenditure,
actionType: Action,
): DecisionMethodOption[] => {
const { user } = useAppContext();
const isPermissionsEnabled = useCheckIfUserHasPermissions(actionType);

const userIsCreator = user?.walletAddress === expenditure.ownerAddress;

Expand All @@ -21,15 +17,6 @@ export const useGetReleaseDecisionMethodItems = (
}

return [
...(isPermissionsEnabled || (!isPermissionsEnabled && !userIsCreator)
? [
{
label: formatText({ id: 'decisionMethod.permissions' }),
value: DecisionMethod.Permissions,
isDisabled: !isPermissionsEnabled,
},
]
: []),
...(userIsCreator
? [
{
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@
"motion.staking.input.error.moreThanRemaining": "You can't stake more than remaining stake",
"action.executed.permissions": "Executed using permissions.",
"action.executed.permissions.description": "Member used permissions to create this action.",
"action.executed.creator.description": "Member used payment creator to create this action.",
"action.executed.creator.description": "Payment creator released this payment.",
"action.executed.permissions.overview": "Overview",
"action.executed.permissions.member": "Member",
"action.executed.permissions.permission": "Permission",
Expand Down

0 comments on commit d808b86

Please sign in to comment.