Skip to content

Commit

Permalink
Merge branch 'dev' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Sep 13, 2023
2 parents c60c87e + 5d8c104 commit 46c9062
Show file tree
Hide file tree
Showing 74 changed files with 647 additions and 215 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"moment": "^2.29.1",
"node-sass": "^4.14.1",
"openpgp": "4.10.4",
"pluralize": "^8.0.0",
"query-string": "^7.1.0",
"react": "^17.0.1",
"react-aria-menubutton": "^7.0.3",
Expand Down
6 changes: 4 additions & 2 deletions src/events/CommonEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ export enum CommonEvent {
CommonCreated = "common-created",
CommonUpdated = "common-updated",
CommonDeleted = "common-deleted",
ProjectCreated = "project-created",
ProjectCreatedOrUpdated = "project-created-or-updated",
ProjectUpdated = "project-updated",
}

export interface CommonEventToListener {
[CommonEvent.CommonCreated]: (common: Common) => void;
[CommonEvent.CommonUpdated]: (common: Common) => void;
[CommonEvent.CommonDeleted]: (deletedCommonId: string) => void;
[CommonEvent.ProjectCreated]: (projectsStateItem: ProjectsStateItem) => void;
[CommonEvent.ProjectCreatedOrUpdated]: (
projectsStateItem: ProjectsStateItem,
) => void;
[CommonEvent.ProjectUpdated]: (
projectsStateItem: { commonId: string } & Partial<
Omit<ProjectsStateItem, "commonId">
Expand Down
23 changes: 12 additions & 11 deletions src/pages/App/handlers/CommonHandler/CommonHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ const CommonHandler: FC = () => {
}, []);

useEffect(() => {
const handler: CommonEventToListener[CommonEvent.ProjectCreated] = (
projectsStateItem,
) => {
dispatch(
multipleSpacesLayoutActions.addProjectToBreadcrumbs(projectsStateItem),
);
dispatch(commonLayoutActions.addProject(projectsStateItem));
dispatch(projectsActions.addProject(projectsStateItem));
};
const handler: CommonEventToListener[CommonEvent.ProjectCreatedOrUpdated] =
(projectsStateItem) => {
dispatch(
multipleSpacesLayoutActions.addOrUpdateProjectInBreadcrumbs(
projectsStateItem,
),
);
dispatch(commonLayoutActions.addOrUpdateProject(projectsStateItem));
dispatch(projectsActions.addOrUpdateProject(projectsStateItem));
};

CommonEventEmitter.on(CommonEvent.ProjectCreated, handler);
CommonEventEmitter.on(CommonEvent.ProjectCreatedOrUpdated, handler);

return () => {
CommonEventEmitter.off(CommonEvent.ProjectCreated, handler);
CommonEventEmitter.off(CommonEvent.ProjectCreatedOrUpdated, handler);
};
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ export default function DiscussionDetailModal({
);

useEffect(() => {
if (discussion?.circleVisibility) {
if (discussion?.circleVisibilityByCommon?.[governance.commonId]) {
(async () => {
const governanceCircles = await getCommonGovernanceCircles(
governance.id,
);
const filteredByIdCircles = getFilteredByIdCircles(
governanceCircles ? Object.values(governanceCircles) : null,
discussion?.circleVisibility,
discussion?.circleVisibilityByCommon?.[governance.commonId],
);
const names = getCirclesWithLowestTier(filteredByIdCircles)
.map(({ name }) => name)
Expand All @@ -102,7 +102,7 @@ export default function DiscussionDetailModal({
return () => {
dispatch(chatActions.clearCurrentDiscussionMessageReply());
};
}, [governance.id, discussion]);
}, [governance.id, governance.commonId, discussion]);

const sendMessage = useCallback(
(message: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ export default function DiscussionItemComponent({
const date = new Date();

useEffect(() => {
if (discussion.circleVisibility) {
if (discussion.circleVisibilityByCommon) {
(async () => {
const governanceCircles = await getCommonGovernanceCircles(
governance.id,
);
const filteredByIdCircles = getFilteredByIdCircles(
governanceCircles ? Object.values(governanceCircles) : null,
discussion.circleVisibility,
discussion.circleVisibilityByCommon?.[governance.commonId],
);
const names = getCirclesWithLowestTier(filteredByIdCircles)
.map(({ name }) => name)
.join(", ");
setCircleNames(names);
})();
}
}, [governance.id, discussion.circleVisibility]);
}, [governance.id, governance.commonId, discussion.circleVisibilityByCommon]);

return (
<div className="discussion-item-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function EmptyTabComponent({
className="button-blue empty-tab-content-wrapper__button"
onClick={handleModalOpen}
>
Join the effort
Join
</button>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ export default function CreateCommonModal(props: CreateCommonModalProps) {
notificationsAmount: 0,
};

CommonEventEmitter.emit(CommonEvent.ProjectCreated, projectsStateItem);
CommonEventEmitter.emit(
CommonEvent.ProjectCreatedOrUpdated,
projectsStateItem,
);
CommonEventEmitter.emit(
CommonEvent.CommonCreated,
createdCommonData.common,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,20 @@ export default function CommonDetail(props: CommonDetailProps = {}) {
const circleIds = new Set(
commonMember ? Object.values(commonMember.circles.map) : [],
);
return discussions.filter(({ circleVisibility, moderation }) => {
return discussions.filter(({ circleVisibilityByCommon, moderation }) => {
if (moderation?.flag === ModerationFlags.Hidden) {
return false;
}

const circleVisibility = circleVisibilityByCommon?.[id];
if (!circleVisibility?.length) {
return true;
}
return circleVisibility?.some((discussionCircleId) =>
circleIds.has(discussionCircleId),
);
});
}, [discussions, commonMember]);
}, [discussions, commonMember, id]);

const activeProposals = useMemo(
() => proposals.filter((d) => checkIsCountdownState(d)),
Expand Down
36 changes: 31 additions & 5 deletions src/pages/OldCommon/interfaces/CreateProposalPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,66 @@ import {
Survey,
} from "@/shared/models/governance/proposals";

type CircleVisibility = string[] | null;

interface CreateFundsAllocation {
type: ProposalsTypes.FUNDS_ALLOCATION;
args: Omit<FundsAllocation["data"]["args"], "proposerId">;
}

interface CreateMemberAdmittance {
type: ProposalsTypes.MEMBER_ADMITTANCE;
args: Omit<MemberAdmittance["data"]["args"], "proposerId"> & {
args: Omit<
MemberAdmittance["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
contributionSourceType?: ContributionSourceType;
feeMonthly: PaymentAmount | null;
feeOneTime: PaymentAmount | null;
fromSupportersFlow?: boolean;
receiveEmails?: boolean;
userWhatsapp?: boolean;
circleVisibility?: CircleVisibility;
};
}

interface CreateAssignCircle {
type: ProposalsTypes.ASSIGN_CIRCLE;
args: Omit<AssignCircle["data"]["args"], "proposerId">;
args: Omit<
AssignCircle["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
circleVisibility?: CircleVisibility;
};
}
interface CreateRemoveCircle {
type: ProposalsTypes.REMOVE_CIRCLE;
args: Omit<RemoveCircle["data"]["args"], "proposerId">;
args: Omit<
RemoveCircle["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
circleVisibility?: CircleVisibility;
};
}

interface CreateSurvey {
type: ProposalsTypes.SURVEY;
args: Omit<Survey["data"]["args"], "proposerId">;
args: Omit<
Survey["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
circleVisibility?: CircleVisibility;
};
}

interface CreateDeleteCommon {
type: ProposalsTypes.DELETE_COMMON;
args: Omit<DeleteCommon["data"]["args"], "proposerId">;
args: Omit<
DeleteCommon["data"]["args"],
"proposerId" | "circleVisibilityByCommon"
> & {
circleVisibility?: CircleVisibility;
};
}

interface Request<P, R> {
Expand Down
9 changes: 6 additions & 3 deletions src/pages/common/components/ChatComponent/ChatComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,12 @@ export default function ChatComponent({

useEffect(() => {
if (commonId && !isChatChannel) {
fetchDiscussionUsers(commonId, discussion?.circleVisibility);
fetchDiscussionUsers(
commonId,
discussion?.circleVisibilityByCommon?.[commonId],
);
}
}, [commonId, discussion?.circleVisibility]);
}, [commonId, discussion?.circleVisibilityByCommon]);

useEffect(() => {
if (chatChannel?.id) {
Expand Down Expand Up @@ -577,7 +580,7 @@ export default function ChatComponent({

return (
<span className={styles.permissionsText} onClick={onJoinCommon}>
{directParent ? "Join the space" : "Join the effort"}
Join
</span>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/common/components/ChatComponent/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ChatItem {
proposal?: Proposal;
discussion?: Discussion;
chatChannel?: ChatChannel;
circleVisibility: string[];
circleVisibility?: string[];
lastSeenItem?: CommonFeedObjectUserUnique["lastSeen"];
lastSeenAt?: CommonFeedObjectUserUnique["lastSeenAt"];
seenOnce?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/common/components/CommonHeader/CommonHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const CommonHeader: FC<CommonHeaderProps> = (props) => {
details = [],
isProject = false,
withJoin = true,
joinButtonText = isProject ? "Join the space" : "Join the effort",
joinButtonText = "Join",
} = props;
const { isJoinAllowed, onJoinCommon } = useCommonDataContext();
const isTabletView = useIsTabletView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const CommonEntranceJoin: FC<CommonEntranceJoinProps> = (props) => {
: onJoinCommon
}
>
Join the {isProject ? "space" : "effort"}
Join
</Button>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export const checkHasAccessToChat = (
return false;
}

const { circleVisibility = [] } = chatItem;

return (
!chatItem.circleVisibility.length ||
chatItem.circleVisibility.some((circleId) =>
userCircleIds.includes(circleId),
)
!circleVisibility.length ||
circleVisibility.some((circleId) => userCircleIds.includes(circleId))
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Modal } from "@/shared/components";
import { ErrorText } from "@/shared/components/Form";
import { Circle } from "@/shared/models";
import { Button, ButtonVariant } from "@/shared/ui-kit";
import { pluralizeWord } from "@/shared/utils";
import { commonActions } from "@/store/states";
import styles from "./AssignCircleModal.module.scss";

Expand Down Expand Up @@ -62,7 +63,7 @@ export default function AssignCircleModal({
onClose={handleClose}
hideCloseButton={isAdding}
className={styles.modal}
title={`Add ${memberName} to ${selectedCircle?.name}?`}
title={`Add ${memberName} to ${pluralizeWord(selectedCircle?.name)}?`}
>
<div className={styles.content}>
<div className={styles.text}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useModal } from "@/shared/hooks";
import { ContextMenuItem as Item } from "@/shared/interfaces";
import { Circle } from "@/shared/models";
import { ContextMenu, ContextMenuRef } from "@/shared/ui-kit";
import { pluralizeWord } from "@/shared/utils";
import AssignCircleModal from "./AssignCircleModal";
import elementDropdownStyles from "./MemberDropdown.module.scss";

Expand Down Expand Up @@ -31,7 +32,7 @@ const MemberDropdown: FC<MemberDropdownProps> = (props) => {
() =>
notMemberCircles.map((circle) => ({
id: circle.id,
text: `Add to ${circle.name}`,
text: `Add to ${pluralizeWord(circle.name)}`,
onClick: () => {
setSelectedCircle(circle);
onOpen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
commonMember,
feedItemFollow,
getNonAllowedItems,
feedItemUserMetadata,
},
{
report: onReportModalOpen,
Expand Down Expand Up @@ -246,7 +247,10 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
}

const circleVisibility = governanceCircles
? getVisibilityString(governanceCircles, discussion?.circleVisibility)
? getVisibilityString(
governanceCircles,
discussion?.circleVisibilityByCommon?.[commonId],
)
: undefined;

return (
Expand Down Expand Up @@ -324,6 +328,7 @@ const DiscussionFeedCard = forwardRef<FeedItemRef, DiscussionFeedCardProps>(
isLoading={isLoading}
menuItems={menuItems}
seenOnce={feedItemUserMetadata?.seenOnce}
seen={feedItemUserMetadata?.seen}
ownerId={item.userId}
discussionPredefinedType={discussion?.predefinedType}
>
Expand Down
Loading

0 comments on commit 46c9062

Please sign in to comment.