Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release fix refetch contributions after redeem #2357

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/features/common/Layout/MyForestContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ interface UserInfo {
areaConserved: number;
};
}
type ContributionsQueryRefetchType = ReturnType<
typeof trpc.myForest.contributions.useQuery
>['refetch'];

type LeaderboardQueryRefetchType = ReturnType<
typeof trpc.myForest.leaderboard.useQuery
>['refetch'];

interface MyForestContextInterface {
projectListResult: ProjectListResponse | undefined;
contributionsResult: ContributionsResponse | undefined;
Expand All @@ -41,6 +49,8 @@ interface MyForestContextInterface {
userInfo: UserInfo | null;
setUserInfo: SetState<UserInfo | null>;
contributionStats: ContributionStats | undefined;
refetchContributions: ContributionsQueryRefetchType;
refetchLeaderboard: LeaderboardQueryRefetchType;
}

const MyForestContext = createContext<MyForestContextInterface | null>(null);
Expand Down Expand Up @@ -196,6 +206,8 @@ export const MyForestProvider: FC = ({ children }) => {
userInfo,
setUserInfo,
contributionStats,
refetchContributions: _contributions.refetch,
refetchLeaderboard: _leaderboard.refetch,
}),
[
projectListResult,
Expand All @@ -213,6 +225,8 @@ export const MyForestProvider: FC = ({ children }) => {
userInfo,
setUserInfo,
contributionStats,
_contributions.refetch,
_leaderboard.refetch,
]
);

Expand Down
4 changes: 4 additions & 0 deletions src/features/user/Profile/ProfileCard/RedeemModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EnterRedeemCode,
} from '../../../../common/RedeemCode';
import { useTenant } from '../../../../common/Layout/TenantContext';
import { useMyForest } from '../../../../common/Layout/MyForestContext';
interface RedeemModal {
redeemModalOpen: boolean;
handleRedeemModalClose: () => void;
Expand All @@ -38,6 +39,7 @@ export default function RedeemModal({
} = useUserProps();
const { setErrors, errors: apiErrors } =
React.useContext(ErrorHandlingContext);
const { refetchContributions, refetchLeaderboard } = useMyForest();
const [inputCode, setInputCode] = React.useState<string | undefined>('');
const [redeemedCodeData, setRedeemedCodeData] = React.useState<
RedeemedCodeData | undefined
Expand All @@ -64,6 +66,8 @@ export default function RedeemModal({
const cloneUser = { ...user };
cloneUser.score.received = cloneUser.score.received + res.units;
setUser(cloneUser);
refetchContributions();
refetchLeaderboard();
}
} catch (err) {
const serializedErrors = handleError(err as APIError);
Expand Down
Loading