Skip to content

Commit

Permalink
CW-1010 Changed useCommon to useFullCommonData
Browse files Browse the repository at this point in the history
  • Loading branch information
MeyerPV committed Dec 20, 2022
1 parent d861fe7 commit 2e671a7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
// Disallow leading or trailing decimal points in numeric literals
"no-floating-decimal": 2,
// Warn against shorthand Types conversions
"no-implicit-coercion": 1,
"no-implicit-coercion": 0,
// Warn against function declarations and expressions inside loop statements
"no-loop-func": 1,
// Disallow new operators with the Function object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC } from "react";
import { ViewportBreakpointVariant } from "@/shared/constants";
import { useIsTabletView } from "@/shared/hooks/viewport";
import { Common, PaymentAmount } from "@/shared/models";
import { Common } from "@/shared/models";
import { MemberAdmittanceLimitations } from "@/shared/models/governance/proposals";
import { Container } from "@/shared/ui-kit";
import { CommonCard } from "../../../../../CommonCard";
Expand Down Expand Up @@ -30,16 +30,16 @@ const CommonEntranceInfo: FC<CommonEntranceInfoProps> = (props) => {
<CommonCard className={styles.container} hideCardStyles={isTabletView}>
<h3 className={styles.title}>Entrance</h3>
<dl className={styles.list}>
{Boolean(limitations?.minFeeOneTime) && (
{!!limitations?.minFeeOneTime && (
<CommonEntranceItem
text="Minimal single contribution"
amount={limitations?.minFeeOneTime as PaymentAmount}
amount={limitations?.minFeeOneTime}
/>
)}
{Boolean(limitations?.minFeeMonthly) && (
{!!limitations?.minFeeMonthly && (
<CommonEntranceItem
text="Minimal monthly contribution"
amount={limitations?.minFeeMonthly as PaymentAmount}
amount={limitations?.minFeeMonthly}
bySubscription
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
.joinButton {
max-width: 8.5rem;
margin-top: 1.75rem;
padding-left: 0;
padding-right: 0;
padding: 0 0.875rem;

@include tablet {
margin-top: 1.625rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { FC, useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { selectUser } from "@/pages/Auth/store/selectors";
import { CommonService } from "@/services";
import { useCommon } from "@/shared/hooks/useCases";
import { useFullCommonData } from "@/shared/hooks/useCases";
import { Common } from "@/shared/models";
import { Button, ButtonSize, ButtonVariant } from "@/shared/ui-kit";
import styles from "./CommonEntranceJoin.module.scss";
Expand All @@ -20,23 +20,20 @@ const CommonEntranceJoin: FC<CommonEntranceJoinProps> = (props) => {
const isProject = Boolean(common.directParent);
const parentId = common.directParent?.commonId;
const {
data: parentCommon,
fetched: isParentCommonFetched,
fetchCommon: fetchParentCommon,
setCommon: setParentCommon,
} = useCommon();
data: commonData,
fetched: isCommonDataFetched,
fetchCommonData,
} = useFullCommonData();

useEffect(() => {
if (!parentId) {
if (!common.id) {
return;
}

if (parentId) {
fetchParentCommon(parentId);
} else {
setParentCommon(null);
fetchCommonData(common.id);
}
}, [parentId, fetchParentCommon, setParentCommon]);
}, [common, fetchCommonData]);

useEffect(() => {
if (!parentId || !user?.uid) {
Expand All @@ -52,17 +49,17 @@ const CommonEntranceJoin: FC<CommonEntranceJoinProps> = (props) => {
})();
}, [user, parentId]);

if (!isParentCommonFetched && isProject && user) {
if (!isCommonDataFetched && isProject && user) {
return null;
}

return (
<>
{isProject && parentCommon?.name && (
{isProject && commonData?.parent?.name && (
<p className={styles.joinHint}>
<strong>{common.name}</strong> is a project in the{" "}
<strong>{parentCommon.name}</strong> common. Only common members can
join the project.
<strong>{commonData?.parent.name}</strong> common. Only common members
can join the project.
</p>
)}
{((withJoinRequest && !isProject) ||
Expand Down
3 changes: 3 additions & 0 deletions src/shared/hooks/useCases/useFullCommonData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CommonEventEmitter,
CommonEventToListener,
} from "@/events";
import { last } from "lodash";
import { CommonService, GovernanceService } from "@/services";
import { LoadingState } from "@/shared/interfaces";
import { Common, Governance } from "@/shared/models";
Expand All @@ -13,6 +14,7 @@ interface Data {
governance: Governance;
parentCommons: Common[];
subCommons: Common[];
parent?: Common;
}

type State = LoadingState<Data | null>;
Expand Down Expand Up @@ -64,6 +66,7 @@ export const useFullCommonData = (): Return => {
governance,
parentCommons,
subCommons,
parent: last(parentCommons),
},
});
} catch (error) {
Expand Down

0 comments on commit 2e671a7

Please sign in to comment.