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

Added Pinning functionality in the create post modal. #1129

Closed
45 changes: 44 additions & 1 deletion src/screens/OrgPost/OrgPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import SortIcon from '@mui/icons-material/Sort';
import Row from 'react-bootstrap/Row';
import Modal from 'react-bootstrap/Modal';
import { Form } from 'react-bootstrap';
import { Col, Form } from 'react-bootstrap';
import { useMutation, useQuery } from '@apollo/client';
import Button from 'react-bootstrap/Button';
import { toast } from 'react-toastify';
Expand All @@ -20,6 +20,7 @@
import { errorHandler } from 'utils/errorHandler';
import Loader from 'components/Loader/Loader';
import OrganizationScreen from 'components/OrganizationScreen/OrganizationScreen';
import { TOGGLE_PINNED_POST } from 'GraphQl/Mutations/mutations';

interface InterfaceOrgPost {
_id: string;
Expand All @@ -45,11 +46,27 @@
postinfo: '',
postImage: '',
postVideo: '',
pinned: false,
});
const [sortingOption, setSortingOption] = useState('latest');
const [showTitle, setShowTitle] = useState(true);

const currentUrl = window.location.href.split('=')[1];
const [toggle] = useMutation(TOGGLE_PINNED_POST);
const togglePostPin = async (_id: string): Promise<void> => {
try {
const { data } = await toggle({

Check warning on line 58 in src/screens/OrgPost/OrgPost.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/OrgPost/OrgPost.tsx#L57-L58

Added lines #L57 - L58 were not covered by tests
variables: {
id: _id,
},
});
return data;

Check warning on line 63 in src/screens/OrgPost/OrgPost.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/OrgPost/OrgPost.tsx#L63

Added line #L63 was not covered by tests
} catch (error: any) {
console.log(error);

Check warning on line 65 in src/screens/OrgPost/OrgPost.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/OrgPost/OrgPost.tsx#L65

Added line #L65 was not covered by tests
/* istanbul ignore next */
errorHandler(t, error);
}
};

const showInviteModal = (): void => {
setPostModalIsOpen(true);
Expand All @@ -61,6 +78,7 @@
postinfo: '',
postImage: '',
postVideo: '',
pinned: false,
});
};

Expand Down Expand Up @@ -95,6 +113,7 @@
postinfo: _postinfo,
postImage,
postVideo,
pinned,
} = postformState;

const posttitle = _posttitle.trim();
Expand All @@ -111,17 +130,24 @@
text: postinfo,
organizationId: currentUrl,
file: postImage || postVideo,
pinned: pinned,
},
});
/* istanbul ignore next */
if (data) {
if (pinned) {
// Call togglePostPin to update the pinning information in the backend
await togglePostPin(data.createPost._id);
toast.success('Post Pinned Successfully');
}
toast.success('Congratulations! You have Posted Something.');
refetch();
setPostFormState({
posttitle: '',
postinfo: '',
postImage: '',
postVideo: '',
pinned: false,
});
setPostModalIsOpen(false); // close the modal
}
Expand Down Expand Up @@ -481,6 +507,23 @@
)}
</>
)}
<Row className="mb-3">
<Col>
<Form.Label htmlFor="ispinnedpost">Pinned Post</Form.Label>
<Form.Switch
id="ispinnedpost"
data-testid="ispinnedpost"
type="checkbox"
defaultChecked={postformState.pinned}
onChange={(e): void => {
setPostFormState({

Check warning on line 519 in src/screens/OrgPost/OrgPost.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/OrgPost/OrgPost.tsx#L518-L519

Added lines #L518 - L519 were not covered by tests
...postformState,
pinned: e.target.checked,
});
}}
/>
</Col>
</Row>
</Modal.Body>
<Modal.Footer>
<Button
Expand Down
Loading