Skip to content

Commit

Permalink
refresh list after updating status
Browse files Browse the repository at this point in the history
  • Loading branch information
moshfeu committed Jul 1, 2021
1 parent d1488bf commit 52217f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
30 changes: 23 additions & 7 deletions src/Me/MentorshipRequests/MentorshipRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const MentorshipReq = () => {
await updateReqStatus(
{ id: selectedReq.id, userId },
STATUS.cancelled,
message
message,
'mentee'
);
closeCancelModal();
};
Expand Down Expand Up @@ -78,8 +79,18 @@ const MentorshipReq = () => {
setLoadingState(false);
}
}, [userId]);

const updateReqStatus = async ({ id, userId }, nextStatus, reason) => {
/**
* @param {import('../../types/models').User} user
* @param {import('../../helpers/mentorship').Status} nextStatus
* @param {string} reason
* @param {'mentee' | 'mentor'} listType
*/
const updateReqStatus = async (
{ id, userId },
nextStatus,
reason,
listType = 'mentor'
) => {
const { success, mentorship } = await updateMentorshipReqStatus(
id,
userId,
Expand All @@ -91,15 +102,20 @@ const MentorshipReq = () => {

if (!success) return;

const itemIndex = mentorState.findIndex(s => s.id === id);
const item = mentorState[itemIndex];
let newState = [...mentorState];
const [list, setList] =
listType === 'mentor'
? [mentorState, setMentorState]
: [menteeState, setMenteeState];

const itemIndex = list.findIndex(s => s.id === id);
const item = list[itemIndex];
let newState = [...list];
newState.splice(itemIndex, 1, {
...item,
status: mentorship.status,
});

setMentorState(newState);
setList(newState);
};

const [openAcceptModal] = useModal(
Expand Down
7 changes: 0 additions & 7 deletions src/Me/MentorshipRequests/UsersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@ import { getAvatarUrl } from '../../helpers/avatar';
import ReqContent from './ReqContent';
import { formatRequestTime, Status } from '../../helpers/mentorship';
import { RichList, RichItem } from '../components/RichList';
import { Loader } from '../../components/Loader';
import styled from 'styled-components';
import { STATUS } from '../../helpers/mentorship';
import { ReactComponent as UserWasRemovedIcon } from '../../assets/me/icon-user-remove.svg';
import { MentorshipRequest } from '../../types/models';
import { useExpendableRichItems } from '../components/RichList/RichList';
import { RichItemTagTheme } from '../components/RichList/ReachItemTypes';

const Spinner = styled(Loader)`
position: absolute;
left: calc(50% - 10px);
`;

const UserWasRemoved = styled.div`
display: grid;
grid-template-columns: 21px auto;
Expand Down Expand Up @@ -144,7 +138,6 @@ export const UsersList = ({

return (
<>
{isLoading && <Spinner />}
<RichList>
{renderList({
requests,
Expand Down
1 change: 1 addition & 0 deletions src/Me/Modals/MentorshipRequestModals/CancelModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const CancelModal = ({ username, onSave, onClose }: CanceledModalProps) => {
title="Cancel mentorship request"
onClose={onClose}
isLoading={isLoading}
submitLabel="Cancel"
onSave={() => {
setIsLoading(true);
onSave(reasonOption === '3' ? reason.current : REASONS[reasonOption]);
Expand Down
9 changes: 2 additions & 7 deletions src/Me/Modals/MentorshipRequestModals/DeclineModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import BodyStyle from './style';
import { useRef, useState } from 'react';
import { Modal } from '../Modal';
import TextArea from '../../components/Textarea';
import { Loader } from '../../../components/Loader';
import styled from 'styled-components';
import FormField from '../../components/FormField';

const Spinner = styled(Loader)`
position: absolute;
top: 25%;
`;

const Body = styled(BodyStyle)`
justify-content: flex-start;
p {
Expand All @@ -33,13 +27,14 @@ const DeclineModal = ({ username, onSave, onClose }: DeclineModalProps) => {
center
title="Decline Mentorship"
onClose={onClose}
isLoading={loadingState}
submitLabel="Decline"
onSave={() => {
setLoadingState(true);
onSave(message.current);
}}
>
<Body>
{loadingState && <Spinner />}
<div>
<p>
You have declined <b>{username}</b> and that’s ok, now is not a good
Expand Down

0 comments on commit 52217f8

Please sign in to comment.