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

Adding use hook for quantifier notification bar #1074

Merged
merged 5 commits into from
Jun 21, 2023
Merged
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
31 changes: 31 additions & 0 deletions packages/api-types/out/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export interface paths {
/** Verifies a user's signature and returns a JWT token */
post: operations['EthSignatureController_login'];
};
'/api/auth/eth-signature/refresh': {
/** Verifies a refreshToken and returns a JWT token */
post: operations['EthSignatureController_token'];
};
'/api/communities': {
get: operations['CommunityController_findAll'];
/** Create a new community */
Expand Down Expand Up @@ -926,12 +930,18 @@ export interface components {
LoginResponseDto: {
/** @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2MmIwNmY3NjU1ODA0YjE2MjllODQxNTkiLCJpZGVudGl0eUV0aEFkZHJlc3MiOiIweGEzMmFFQ2RhNzUyY0Y0RUY4OTk1NmU4M2Q2MEMwNDgzNWQ0RkE4NjciLCJyb2xlcyI6WyJVU0VSIiwiQURNSU4iXSwiaXNSZWZyZXNoIjpmYWxzZSwiaWF0IjoxNjcwMzE1OTk4LCJleHAiOjE2NzAzMTk1OTh9.qKvucMZLVbz_1TnsxaSqYX1i5CSpver6fFJTf3pABVA */
accessToken: string;
/** @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2MmIwNmY3NjU1ODA0YjE2MjllODQxNTkiLCJpZGVudGl0eUV0aEFkZHJlc3MiOiIweGEzMmFFQ2RhNzUyY0Y0RUY4OTk1NmU4M2Q2MEMwNDgzNWQ0RkE4NjciLCJyb2xlcyI6WyJVU0VSIiwiQURNSU4iXSwiaXNSZWZyZXNoIjpmYWxzZSwiaWF0IjoxNjcwMzE1OTk4LCJleHAiOjE2NzAzMTk1OTh9.qKvucMZLVbz_1TnsxaSqYX1i5CSpver6fFJTf3pABVA */
refreshToken: string;
/** @example 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 */
identityEthAddress: string;
/** @example bearer */
tokenType: string;
user: components['schemas']['User'];
};
GenerateTokenDto: {
/** @example eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2MmIwNmY3NjU1ODA0YjE2MjllODQxNTkiLCJpZGVudGl0eUV0aEFkZHJlc3MiOiIweGEzMmFFQ2RhNzUyY0Y0RUY4OTk1NmU4M2Q2MEMwNDgzNWQ0RkE4NjciLCJyb2xlcyI6WyJVU0VSIiwiQURNSU4iXSwiaXNSZWZyZXNoIjpmYWxzZSwiaWF0IjoxNjcwMzE1OTk4LCJleHAiOjE2NzAzMTk1OTh9.qKvucMZLVbz_1TnsxaSqYX1i5CSpver6fFJTf3pABVA */
refreshToken: string;
};
CreateCommunityInputDto: {
/** @example banklessdao.givepraise.xyz */
hostname: string;
Expand Down Expand Up @@ -2062,6 +2072,27 @@ export interface operations {
};
};
};
/** Verifies a refreshToken and returns a JWT token */
EthSignatureController_token: {
parameters: {
header: {
host: string;
};
};
requestBody: {
content: {
'application/json': components['schemas']['GenerateTokenDto'];
};
};
responses: {
/** @description Tokens generated successfully */
201: {
content: {
'application/json': components['schemas']['LoginResponseDto'];
};
};
};
};
CommunityController_findAll: {
parameters: {
query: {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/openapi.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Link } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { AllActiveUserQuantificationPeriods } from '@/model/periods/periods';
import {
AllActiveUserQuantificationPeriods,
useLoadAllQuantifyPeriodDetails,
} from '@/model/periods/periods';
import { PeriodDetailsDto } from '@/model/periods/dto/period-details.dto';

interface QuantifierPeriodMessageProps {
Expand All @@ -18,15 +21,17 @@ const QuantifierPeriodMessage = ({
};

export const ActiveUserQuantificationsMessage = (): JSX.Element | null => {
useLoadAllQuantifyPeriodDetails();
const activeUserQuantificationPeriods = useRecoilValue(
AllActiveUserQuantificationPeriods
);
if (
!activeUserQuantificationPeriods ||
!Array.isArray(activeUserQuantificationPeriods) ||
activeUserQuantificationPeriods.length === 0
)
) {
return null;
}

return (
<div>
Expand Down
27 changes: 27 additions & 0 deletions packages/frontend/src/model/periods/periods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,33 @@ export const AllActiveUserQuantificationPeriods = selector({
},
});

export const useLoadAllQuantifyPeriodDetails = (): void => {
const periods = useRecoilValue(AllPeriods);

const loadPeriodDetails = useRecoilCallback(({ set, snapshot }) => {
return async (periodId: string): Promise<void> => {
await snapshot
.getPromise(DetailedSinglePeriodQuery(periodId))
.then((response) => {
if (isResponseOk(response)) {
const period = response.data;
set(SinglePeriod(period._id), period);
}
});
};
});

React.useEffect(() => {
if (!periods) return;
for (const period of periods) {
if (period.status === 'QUANTIFY' && !period.numberOfPraise) {
// Having no numberOfPraise attribute means that the period details have not been loaded yet.
void loadPeriodDetails(period._id);
}
}
}, [periods, loadPeriodDetails]);
};

const useSaveGiverReceiverPraiseItems = (
response: AxiosResponse<Praise[]> | AxiosError,
listKey: string
Expand Down
Loading