Skip to content

Commit

Permalink
Merge branch 'dev' into cw-2101-mobile-chat-messages-missing
Browse files Browse the repository at this point in the history
  • Loading branch information
roienatan committed Oct 4, 2023
2 parents 7acf4fd + bebde8e commit 1fecf86
Show file tree
Hide file tree
Showing 58 changed files with 577 additions and 140 deletions.
10 changes: 9 additions & 1 deletion src/pages/App/router/configuration/commonSidenavLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { BillingPage_v04 } from "@/pages/billing";
import { ALL_COMMON_PAGE_TABS, CommonPage_v04 } from "@/pages/common";
import { ProjectCreationPage_v04 } from "@/pages/commonCreation";
import {
CommonCreationPage,
ProjectCreationPage_v04,
} from "@/pages/commonCreation";
import { CommonEditingPage_v04 } from "@/pages/commonEditing";
import { CommonFeedPage_v04 } from "@/pages/commonFeed";
import { InboxPage_v04 } from "@/pages/inbox";
Expand Down Expand Up @@ -32,6 +35,11 @@ export const COMMON_SIDENAV_LAYOUT_CONFIGURATION: LayoutConfiguration<CommonSide
type: RouteType.Private,
unauthenticatedRedirectPath: ROUTE_PATHS.HOME,
},
{
path: ROUTE_PATHS.V04_COMMON_CREATION,
exact: true,
component: CommonCreationPage,
},
{
path: ROUTE_PATHS.V04_COMMON,
exact: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ interface LeaveCommonModalProps
memberCircleIds: string[];
onSuccessfulLeave?: () => void;
isSubCommon?: boolean;
subCommonId?: string;
}

const LeaveCommonModal: FC<LeaveCommonModalProps> = (props) => {
Expand All @@ -34,7 +33,6 @@ const LeaveCommonModal: FC<LeaveCommonModalProps> = (props) => {
memberCircleIds = [],
onSuccessfulLeave,
isSubCommon = false,
subCommonId,
} = props;
const {
loading: areMemberAmountsLoading,
Expand Down Expand Up @@ -70,7 +68,7 @@ const LeaveCommonModal: FC<LeaveCommonModalProps> = (props) => {
dispatch(
leaveCommon.request({
payload: {
commonId: isSubCommon && subCommonId ? subCommonId : commonId,
commonId,
userId,
},
callback: (error) => {
Expand All @@ -96,7 +94,7 @@ const LeaveCommonModal: FC<LeaveCommonModalProps> = (props) => {
},
}),
);
}, [dispatch, notify, history, commonId, userId, subCommonId, isSubCommon]);
}, [dispatch, notify, history, commonId, userId]);

useEffect(() => {
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useCallback, useState } from "react";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { selectUser } from "@/pages/Auth/store/selectors";
import { UpdateGovernanceCirclesNamesPayload } from "@/pages/OldCommon/interfaces/UpdateGovernanceCircleName";
import {
updateCommon as updateCommonAction,
updateGovernanceCircleName,
} from "@/pages/OldCommon/store/actions";
import { FileService, Logger } from "@/services";
import { isRequestError } from "@/services/Api";
import { ErrorCode } from "@/shared/constants";
Expand All @@ -11,7 +17,6 @@ import {
UpdateCommonData,
UpdateCommonPayload,
} from "../../../../interfaces";
import { updateCommon as updateCommonAction } from "../../../../store/actions";

interface Return {
isCommonUpdateLoading: boolean;
Expand Down Expand Up @@ -54,6 +59,7 @@ const useCommonUpdate = (commonId?: string): Return => {
const [common, setCommon] = useState<Common | null>(null);
const [error, setError] = useState("");
const dispatch = useDispatch();
const user = useSelector(selectUser());

const updateCommon = useCallback(
async (updatedData: IntermediateUpdateCommonData) => {
Expand Down Expand Up @@ -110,6 +116,30 @@ const useCommonUpdate = (commonId?: string): Return => {
},
}),
);

if (user?.uid && updatedData.roles) {
const circles = updatedData.roles.map((role) => ({
circleId: role.circleId,
newName: role.circleName,
}));
const payload: UpdateGovernanceCirclesNamesPayload = {
commonId,
userId: user.uid,
changes: circles,
};

dispatch(
updateGovernanceCircleName.request({
payload,
callback: (error, updatedCircles) => {
if (error) {
Logger.error(error);
}
setIsCommonUpdateLoading(false);
},
}),
);
}
} catch (err) {
Logger.error(error);
setError(getErrorMessage(err, updatedData.name));
Expand Down
3 changes: 2 additions & 1 deletion src/pages/OldCommon/interfaces/CreateCommonPayload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UploadFile } from "@/shared/interfaces";
import { BaseRule, CommonLink } from "@/shared/models";
import { BaseRule, CommonLink, Roles } from "@/shared/models";
import { MemberAdmittanceLimitations } from "@/shared/models/governance/proposals";
import { TextEditorValue } from "@/shared/ui-kit/TextEditor/types";

Expand Down Expand Up @@ -58,6 +58,7 @@ export interface IntermediateUpdateCommonData {
videoUrl?: string;
gallery?: UploadFile[];
links?: CommonLink[];
roles?: Roles;
}

export interface UpdateCommonData {
Expand Down
18 changes: 18 additions & 0 deletions src/pages/OldCommon/interfaces/UpdateGovernanceCircleName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import firebase from "firebase/app";

interface NewCircle {
circleId: string;
newName: string;
}

export interface UpdateGovernanceCirclesNamesPayload {
commonId: string;
userId: string;
changes: NewCircle[];
}

export interface UpdateGovernanceCirclesNamesResponse {
circles: NewCircle[];
message: string;
updatedAt: firebase.firestore.Timestamp;
}
20 changes: 20 additions & 0 deletions src/pages/OldCommon/store/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import {
ImmediateContributionResponse,
} from "../interfaces";
import { UpdateDiscussionMessageDto } from "../interfaces/UpdateDiscussionMessageDto";
import {
UpdateGovernanceCirclesNamesPayload,
UpdateGovernanceCirclesNamesResponse,
} from "../interfaces/UpdateGovernanceCircleName";
import { CommonsActionTypes } from "./constants";

export const createGovernance = createAsyncAction(
Expand Down Expand Up @@ -369,6 +373,22 @@ export const updateGovernanceRules = createAsyncAction(
Error
>();

export const updateGovernanceCircleName = createAsyncAction(
CommonsActionTypes.UPDATE_GOVERNANCE_CIRCLE_NAME,
CommonsActionTypes.UPDATE_GOVERNANCE_CIRCLE_NAME_SUCCESS,
CommonsActionTypes.UPDATE_GOVERNANCE_CIRCLE_NAME_FAILURE,
)<
{
payload: UpdateGovernanceCirclesNamesPayload;
callback: (
error: Error | null,
updatedCircles?: UpdateGovernanceCirclesNamesResponse,
) => void;
},
UpdateGovernanceCirclesNamesResponse,
Error
>();

export const createVote = createAsyncAction(
CommonsActionTypes.CREATE_VOTE,
CommonsActionTypes.CREATE_VOTE_SUCCESS,
Expand Down
15 changes: 15 additions & 0 deletions src/pages/OldCommon/store/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ import firebase from "@/shared/utils/firebase";
import { generateCirclesDataForCommonMember } from "../../../shared/utils/generateCircleDataForCommonMember";
import { ChangeVisibilityDto } from "../interfaces/ChangeVisibilityDto";
import { UpdateDiscussionMessageDto } from "../interfaces/UpdateDiscussionMessageDto";
import {
UpdateGovernanceCirclesNamesPayload,
UpdateGovernanceCirclesNamesResponse,
} from "../interfaces/UpdateGovernanceCircleName";

export async function createGovernance(
requestData: CreateGovernancePayload,
Expand Down Expand Up @@ -1204,3 +1208,14 @@ export async function updateGovernanceRules(

return convertObjectDatesToFirestoreTimestamps(data);
}

export async function updateGovernanceCirclesNames(
payload: UpdateGovernanceCirclesNamesPayload,
): Promise<UpdateGovernanceCirclesNamesResponse> {
const { data } = await Api.put<Governance>(
ApiEndpoint.GovernanceUpdateCircleName,
payload,
);

return convertObjectDatesToFirestoreTimestamps(data);
}
4 changes: 4 additions & 0 deletions src/pages/OldCommon/store/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,8 @@ export enum CommonsActionTypes {
UPDATE_GOVERNANCE_RULES = "@COMMONS/UPDATE_GOVERNANCE_RULES",
UPDATE_GOVERNANCE_RULES_SUCCESS = "@COMMONS/UPDATE_GOVERNANCE_RULES_SUCCESS",
UPDATE_GOVERNANCE_RULES_FAILURE = "@COMMONS/UPDATE_GOVERNANCE_RULES_FAILURE",

UPDATE_GOVERNANCE_CIRCLE_NAME = "@COMMONS/UPDATE_GOVERNANCE_CIRCLE_NAME",
UPDATE_GOVERNANCE_CIRCLE_NAME_SUCCESS = "@COMMONS/UPDATE_GOVERNANCE_CIRCLE_NAME_SUCCESS",
UPDATE_GOVERNANCE_CIRCLE_NAME_FAILURE = "@COMMONS/UPDATE_GOVERNANCE_CIRCLE_NAME_FAILURE",
}
23 changes: 23 additions & 0 deletions src/pages/OldCommon/store/saga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
createCommon as createCommonApi,
updateCommon as updateCommonApi,
updateGovernanceRules as updateGovernanceRulesApi,
updateGovernanceCirclesNames as updateGovernanceCircleNameApi,
createProposal as createProposalApi,
fetchCommonList,
fetchCommonDetail,
Expand Down Expand Up @@ -1692,13 +1693,35 @@ export function* updateGovernanceRules(
}
}

export function* updateGovernanceCircleName(
action: ReturnType<typeof actions.updateGovernanceCircleName.request>,
): Generator {
try {
const updatedCircles = (yield call(
updateGovernanceCircleNameApi,
action.payload.payload,
)) as Awaited<ReturnType<typeof updateGovernanceCircleNameApi>>;

yield put(actions.updateGovernanceCircleName.success(updatedCircles));
action.payload.callback(null, updatedCircles);
} catch (error) {
if (isError(error)) {
action.payload.callback(error);
}
}
}

export function* commonsSaga() {
yield takeLatest(actions.createGovernance.request, createGovernance);
yield takeLatest(actions.getCommonsList.request, getCommonsList);
yield takeLatest(
actions.updateGovernanceRules.request,
updateGovernanceRules,
);
yield takeLatest(
actions.updateGovernanceCircleName.request,
updateGovernanceCircleName,
);
yield takeLatest(actions.getCommonsListByIds.request, getCommonsListByIds);
yield takeLatest(actions.getCommonDetail.request, getCommonDetail);
yield takeLatest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@
background-color: $white;
box-sizing: border-box;
--chat-input-wrapper-height: 3.125rem;

@include tablet {
height: 100%;
margin-top: 0;
}
}

.messages {
height: 100%;
overflow: auto;
//overscroll-behavior: contain;
overscroll-behavior: contain;
display: flex;
flex-direction: column-reverse;
padding: 0.5rem 2rem 0;
//padding-bottom: calc(var(--chat-input-wrapper-height) + 7rem);
padding-bottom: var(--chat-input-wrapper-height);
}

.emptyChat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const ChatMobileModal: FC<ChatMobileModalProps> = (props) => {
{title}
</p>
)}
{children}
<div className={styles.modalChildren}>{children}</div>
</Modal>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
color: $c-neutrals-300;
}
}

.titleTextarea {
height: 3.125rem !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const DiscussionForm: FC<DiscussionFormProps> = (props) => {
styles={{
labelWrapper: styles.textFieldLabelWrapper,
hint: styles.textFieldHint,
input: { default: styles.titleTextarea },
}}
isTextarea
rows={3}
/>
<TextEditor
className={styles.field}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
color: $c-neutrals-300;
}
}

.titleTextarea {
height: 3.125rem !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ const ProposalForm: FC<ProposalFormProps> = (props) => {
styles={{
labelWrapper: styles.textFieldLabelWrapper,
hint: styles.textFieldHint,
input: { default: styles.titleTextarea },
}}
isTextarea
rows={3}
/>
<TextEditor
className={styles.field}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
import { GovernanceActions } from "@/shared/constants";
import { PredefinedTypes } from "@/shared/models";
import { checkIsCountdownState, hasPermission } from "@/shared/utils";
import { getCirclesWithHighestTier, hasPermission } from "@/shared/utils";
import { GetAllowedItemsOptions } from "../../FeedItem";

export function checkIsRemoveDiscussionAllowed(
options: GetAllowedItemsOptions,
) {
if (!options.commonMember) return false;
if (options.discussion?.predefinedType === PredefinedTypes.General)
): boolean {
const { commonMember } = options;

if (
!commonMember ||
options.discussion?.predefinedType === PredefinedTypes.General
) {
return false;
}

const circles = options.governanceCircles || {};
const isDiscussionOwner = commonMember.userId === options.discussion?.ownerId;
const hasPermissionToRemoveDiscussion =
hasPermission({
commonMember: options.commonMember,
governance: {
circles: options.governanceCircles || {},
},
commonMember,
governance: { circles },
key: GovernanceActions.HIDE_OR_UNHIDE_DISCUSSION,
}) || options.commonMember.userId === options.discussion?.ownerId;
}) || isDiscussionOwner;

let isAllowed = hasPermissionToRemoveDiscussion;
if (options.discussion?.proposalId && isAllowed) {
const { proposal } = options;
const hasPermissionToRemoveProposal =
hasPermission({
commonMember: options.commonMember,
governance: {
circles: options.governanceCircles || {},
},
key: GovernanceActions.HIDE_OR_UNHIDE_PROPOSAL,
}) || options.commonMember.userId === options.discussion?.ownerId;
isAllowed =
!!proposal &&
checkIsCountdownState({ state: proposal.state }) &&
hasPermissionToRemoveProposal;
if (!options.discussion?.proposalId) {
return hasPermissionToRemoveDiscussion;
}
return isAllowed;

const circlesWithHighestTier = getCirclesWithHighestTier(
Object.values(circles),
);

return circlesWithHighestTier.some((circle) =>
commonMember.circleIds.includes(circle.id),
);
}
Loading

0 comments on commit 1fecf86

Please sign in to comment.