Skip to content

Commit

Permalink
Added Pinning functionality in the create post modal.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitSharma512 committed Dec 5, 2023
1 parent 441ab0e commit 187829c
Showing 1 changed file with 44 additions and 1 deletion.
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 { Search } from '@mui/icons-material';
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 NotFound from 'components/NotFound/NotFound';
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 @@ function orgPost(): JSX.Element {
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 @@ function orgPost(): JSX.Element {
postinfo: '',
postImage: '',
postVideo: '',
pinned: false,
});
};

Expand Down Expand Up @@ -95,6 +113,7 @@ function orgPost(): JSX.Element {
postinfo: _postinfo,
postImage,
postVideo,
pinned,
} = postformState;

const posttitle = _posttitle.trim();
Expand All @@ -111,17 +130,24 @@ function orgPost(): JSX.Element {
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 @@ function orgPost(): JSX.Element {
)}
</>
)}
<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

0 comments on commit 187829c

Please sign in to comment.