From 1b77bf84c40ba12a2432bf59969fda9e28a925dd Mon Sep 17 00:00:00 2001 From: Shekhar Patel <90516956+duplixx@users.noreply.github.com> Date: Thu, 14 Dec 2023 00:46:57 +0530 Subject: [PATCH 01/30] Update OrgPost.tsx --- src/screens/OrgPost/OrgPost.tsx | 236 ++++++++++---------------------- 1 file changed, 73 insertions(+), 163 deletions(-) diff --git a/src/screens/OrgPost/OrgPost.tsx b/src/screens/OrgPost/OrgPost.tsx index 9f098c291b..3325869e49 100644 --- a/src/screens/OrgPost/OrgPost.tsx +++ b/src/screens/OrgPost/OrgPost.tsx @@ -1,7 +1,6 @@ import type { ChangeEvent } from 'react'; import React, { useState, useEffect } from 'react'; 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'; @@ -45,10 +44,12 @@ function orgPost(): JSX.Element { postinfo: '', postImage: '', postVideo: '', + addMedia: '', }); const [sortingOption, setSortingOption] = useState('latest'); const [showTitle, setShowTitle] = useState(true); - + const [fileType, setFileType] = useState(''); // Added state for file type + const [file, setFile] = useState(null); const currentUrl = window.location.href.split('=')[1]; const showInviteModal = (): void => { @@ -61,6 +62,7 @@ function orgPost(): JSX.Element { postinfo: '', postImage: '', postVideo: '', + addMedia: '', }); }; @@ -87,6 +89,7 @@ function orgPost(): JSX.Element { setDisplayedPosts(newDisplayedPosts); } }, [orgPostListData, sortingOption]); + const createPost = async (e: ChangeEvent): Promise => { e.preventDefault(); @@ -95,6 +98,7 @@ function orgPost(): JSX.Element { postinfo: _postinfo, postImage, postVideo, + addMedia, } = postformState; const posttitle = _posttitle.trim(); @@ -110,10 +114,10 @@ function orgPost(): JSX.Element { title: posttitle, text: postinfo, organizationId: currentUrl, - file: postImage || postVideo, + file: postImage || postVideo || postformState.addMedia, }, }); - /* istanbul ignore next */ + if (data) { toast.success('Congratulations! You have Posted Something.'); refetch(); @@ -122,11 +126,11 @@ function orgPost(): JSX.Element { postinfo: '', postImage: '', postVideo: '', + addMedia: '', }); - setPostModalIsOpen(false); // close the modal + setPostModalIsOpen(false); } } catch (error: any) { - /* istanbul ignore next */ errorHandler(t, error); } }; @@ -135,10 +139,27 @@ function orgPost(): JSX.Element { return ; } - /* istanbul ignore next */ if (orgPostListError) { window.location.assign('/orglist'); } + const handleAddMediaChange = async ( + e: React.ChangeEvent + ): Promise => { + setPostFormState((prevPostFormState) => ({ + ...prevPostFormState, + addMedia: '', + })); + + const selectedFile = e.target.files?.[0]; + + if (selectedFile) { + setFile(selectedFile); + setPostFormState({ + ...postformState, + addMedia: await convertToBase64(selectedFile), + }); + } + }; const handleSearch = (e: any): void => { const { value } = e.target; @@ -188,6 +209,7 @@ function orgPost(): JSX.Element { } return 1; }); + return ( <> @@ -219,62 +241,14 @@ function orgPost(): JSX.Element { title="SearchBy" data-tesid="sea" > - - - {t('searchBy')} - - - { - setShowTitle(false); - e.preventDefault(); - }} - data-testid="Text" - > - {t('Text')} - - { - setShowTitle(true); - e.preventDefault(); - }} - data-testid="searchTitle" - > - {t('Title')} - - + {/* ... Dropdown code ... */} @@ -370,118 +344,53 @@ function orgPost(): JSX.Element { }); }} /> - {!postformState.postVideo && ( - <> - {t('image')} - - ): Promise => { - setPostFormState((prevPostFormState) => ({ - ...prevPostFormState, - postImage: '', - })); - const file = e.target.files?.[0]; - if (file) { - setPostFormState({ - ...postformState, - postImage: await convertToBase64(file), - }); - } - }} - /> + + + {t('addMedia')} + - {postformState.postImage && ( -
- Post Image Preview - -
+ {postformState.addMedia && file && ( +
+ {/* Display preview for both image and video */} + {file.type.startsWith('image') ? ( + Media Preview + ) : ( + )} - - )} - {!postformState.postImage && ( - <> - {t('video')} - => { - setPostFormState((prevPostFormState) => ({ - ...prevPostFormState, - postVideo: '', - })); - const target = e.target as HTMLInputElement; - const file = target.files && target.files[0]; - if (file) { - const videoBase64 = await convertToBase64(file); - setPostFormState({ - ...postformState, - postVideo: videoBase64, - }); + -
- )} - + data-testid="mediaCloseButton" + > + + + )}
+ + +
+
+ + +
+ + +
+ +
+ {sortedPostsList && sortedPostsList.length > 0 ? ( + sortedPostsList.map( + (datas: { + _id: string; + title: string; + text: string; + imageUrl: string; + videoUrl: string; + organizationId: string; + creator: { firstName: string; lastName: string }; + pinned: boolean; + }) => ( + + ) + ) + ) : ( + + )} +
+ + +
+ + + {t('postDetails')} + +
+ + {t('postTitle')} + { + setPostFormState({ + ...postformState, + posttitle: e.target.value, + }); + }} + /> + {t('information')} + { + setPostFormState({ + ...postformState, + postinfo: e.target.value, + }); + }} + /> + + + {t('addMedia')} + + + {postformState.addMedia && file && ( +
+ {/* Display preview for both image and video */} + {file.type.startsWith('image') ? ( + Post Image Preview + ) : ( + + )} + +
+ )} +
+ + + + + +
+
+ + ); +} - // Check if the video is not present after closing - const videoPreviewAfterClose = screen.queryByTestId('mediaPreview'); - expect(videoPreviewAfterClose).toBeNull(); - }); - }); -}); +export default orgPost; From 1f5232f7a306cea626cfd942d9a7f71b1d944669 Mon Sep 17 00:00:00 2001 From: Shekhar Patel <90516956+duplixx@users.noreply.github.com> Date: Sat, 16 Dec 2023 02:10:39 +0530 Subject: [PATCH 09/30] Update OrgPost.tsx --- src/screens/OrgPost/OrgPost.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screens/OrgPost/OrgPost.tsx b/src/screens/OrgPost/OrgPost.tsx index 47855548ce..be798c599d 100644 --- a/src/screens/OrgPost/OrgPost.tsx +++ b/src/screens/OrgPost/OrgPost.tsx @@ -412,7 +412,7 @@ function orgPost(): JSX.Element { {file.type.startsWith('image') ? ( Post Image Preview ) : ( -