Skip to content

Commit

Permalink
Merge pull request #805 from BinaryStudioAcademy/fix/bt-791-render-wa…
Browse files Browse the repository at this point in the history
…iting-approval-label

bt-791:  [BUG] "Waiting for approval" doesn't disappear/change when user is approved (using db)
  • Loading branch information
nikita-remeslov authored Sep 29, 2023
2 parents 5283f87 + 6562401 commit 5e35585
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const CandidateProfile: React.FC<Properties> = ({
email: state.auth.currentUser?.email,
lmsProject: state.lms.lmsData?.project,
}));
const { publishedAt } = useAppSelector(
const { publishedAt, isApproved } = useAppSelector(
(state: RootReducer) => state.talentOnBoarding,
);

Expand Down Expand Up @@ -148,7 +148,7 @@ const CandidateProfile: React.FC<Properties> = ({
{isFifthStep && (
<Button
label={
publishedAt
publishedAt && !isApproved
? 'Your account is waiting for the approval'
: 'Your account is ready!'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ type Properties = {
const SidebarItem: React.FC<Properties> = ({ link, icon, name }) => {
const [isNotificationVisible, setNotificationVisible] = useState(false);

const { isApproved } = useAppSelector(
(state: RootReducer) => state.talentOnBoarding,
const { talentOnBoarding, employerOnBoarding } = useAppSelector(
(state: RootReducer) => state,
);

const isApproved =
(typeof talentOnBoarding.isApproved === 'boolean' &&
talentOnBoarding.isApproved) ||
(typeof employerOnBoarding.isApproved === 'boolean' &&
employerOnBoarding.isApproved);

const handleToggleNotification = useCallback(() => {
if (!isApproved) {
setNotificationVisible(!isNotificationVisible);
}
}, [isNotificationVisible, isApproved]);
}, [isApproved, isNotificationVisible]);

return (
<li className={isApproved ? '' : styles.listItem}>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/bundles/common/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Home: React.FC = () => {
);
}
case UserRole.EMPLOYER: {
return <Navigate to={AppRoute.EMPLOYER_ONBOARDING} />;
return <Navigate to={AppRoute.MY_PROFILE_EMPLOYER} />;
}
default: {
return <Navigate to={AppRoute.SIGN_IN} />;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/bundles/employer-onboarding/store/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const initialState: UserDetailsGeneralCustom = {
cvUrl: null,
photoUrl: null,
companyLogoUrl: null,
publishedAt: '',
};

const { reducer, actions, name } = createSlice({
Expand Down
15 changes: 6 additions & 9 deletions frontend/src/bundles/profile-cabinet/pages/profile-cabinet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ const ProfileCabinet: React.FC = () => {
) {
setIsWaitingForApproval(true);
}
if (talentOnBoarding.isApproved ?? employerOnBoarding.isApproved) {
setIsWaitingForApproval(false);
void dispatch(
storeActions.notify({
type: NotificationType.SUCCESS,
message: 'Profile was approved',
}),
);
}
}, [
dispatch,
employerOnBoarding.isApproved,
Expand All @@ -116,6 +107,12 @@ const ProfileCabinet: React.FC = () => {
talentOnBoarding.publishedAt,
]);

useEffect(() => {
if (talentOnBoarding.isApproved ?? employerOnBoarding.isApproved) {
setIsWaitingForApproval(false);
}
}, [dispatch, employerOnBoarding.isApproved, talentOnBoarding.isApproved]);

const handlePublish = useCallback(() => {
if (currentUser) {
void dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import { FormSubmitProvider } from '~/bundles/common/context/context.js';
import { AppRoute } from '~/bundles/common/enums/enums.js';
import {
useAppDispatch,
useAppSelector,
useCallback,
useEffect,
Expand Down Expand Up @@ -45,9 +44,7 @@ const Onboarding: React.FC = () => {
const [isWaitingForApproval, setIsWaitingForApproval] =
useState<boolean>(false);

const dispatch = useAppDispatch();
const { currentUser } = useAppSelector((state: RootReducer) => state.auth);
const { publishedAt } = useAppSelector(
const { publishedAt, isApproved } = useAppSelector(
(state: RootReducer) => state.talentOnBoarding,
);
const handleNextStep = useCallback((): void => {
Expand Down Expand Up @@ -96,10 +93,16 @@ const Onboarding: React.FC = () => {
}, [location.pathname]);

useEffect(() => {
if (publishedAt) {
if (publishedAt && !isApproved) {
setIsWaitingForApproval(true);
}
}, [currentUser?.id, dispatch, publishedAt]);
}, [isApproved, publishedAt]);

useEffect(() => {
if (isApproved) {
setIsWaitingForApproval(false);
}
}, [isApproved]);
return (
<PageLayout
avatarUrl=""
Expand Down

0 comments on commit 5e35585

Please sign in to comment.