Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Fixed report to send reason and description
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschwinghammer committed Jun 12, 2024
1 parent 371d56f commit 0d5cfb7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 60 deletions.
22 changes: 4 additions & 18 deletions src/main/web/src/organisms/comment/Comment.tsx

Large diffs are not rendered by default.

17 changes: 5 additions & 12 deletions src/main/web/src/organisms/report/Report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@ import * as yup from 'yup';

interface ReportPostProps {
reportOpen: boolean;
setReportReason: React.Dispatch<React.SetStateAction<string>>;
setReportDescription: React.Dispatch<React.SetStateAction<string>>;
handleReportSubmit: () => void;
handleReportSubmit: (reportReason: string, reportDescription: string) => void;
handleClose: () => void;
}

export const Report: React.FC<ReportPostProps> = (props: ReportPostProps) => {
const {
reportOpen,
setReportReason,
setReportDescription,
handleReportSubmit,
handleClose,
} = props;
Expand All @@ -26,15 +22,12 @@ export const Report: React.FC<ReportPostProps> = (props: ReportPostProps) => {
});

const formik = useFormik({
initialValues: {
reportReason: '',
reportDescription: '',
},
initialValues: {reportReason: '', reportDescription: ''},
validationSchema: validationSchema,
onSubmit: (values): void => {
setReportReason(values.reportReason);
setReportDescription(values.reportDescription);
handleReportSubmit();
console.log('Reason:', values.reportReason);
console.log('Description:', values.reportDescription);
handleReportSubmit(values.reportReason, values.reportDescription);
},
});

Expand Down
22 changes: 5 additions & 17 deletions src/main/web/src/scenes/Home/components/post/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,14 @@ export const Post: React.FC<PostModel> = (props: PostModel) => {
};

const [reportOpen, setReportOpen] = useState(false);
const [reportReason, setReportReason] = useState('');
const [reportDescription, setReportDescription] = useState('');

const handleReportClick = (): void => {
setReportOpen(!reportOpen);
};

const handleReportSubmit = (): void => {
sendReportToBackend(reportReason, reportDescription, id, accountId, "post");
const handleReportSubmit = (reason: string, description: string): void => {
sendReportToBackend(reason, description, id, accountId, "post");
setReportOpen(!reportOpen);
setReportReason('');
setReportDescription('');
};

const [likes, setLikes] = useState(likeAmount);
Expand Down Expand Up @@ -209,18 +205,17 @@ export const Post: React.FC<PostModel> = (props: PostModel) => {
<div className="post-infos" style={{marginLeft: marginLeft}}>
<Link to={`/post/?id=${id}`} className="post-button">
<p className="post-title">
{title ? shortenDescription(title, 50): title }</p>
{title ? shortenDescription(title, 50): title }
</p>
</Link>
<div className="post-tags" style={{marginTop: marginTop}}>
{tags && tags.slice(0, 3).map((tag: string, index: number) => (
<Tag name={tag} key={index} index={index} isEventTag={false}/>
))}
</div>

<p className="short-description" style={{ width: width}}>
{postImage && shortDescription ? shortenDescription(shortDescription, 150) : shortDescription}
</p>

<div className="footer">
<Link to={`/user/?id=${userId}`} className="author-link" aria-label="To the author">
{username}
Expand All @@ -241,7 +236,6 @@ export const Post: React.FC<PostModel> = (props: PostModel) => {
/>
</div>
</div>

{menuOpen && (
<div className="post-menu-container">
<PostMenu
Expand All @@ -259,13 +253,7 @@ export const Post: React.FC<PostModel> = (props: PostModel) => {
</div>
)}
{reportOpen && (
<Report
reportOpen={reportOpen}
setReportReason={setReportReason}
setReportDescription={setReportDescription}
handleReportSubmit={handleReportSubmit}
handleClose={handleClose}
/>
<Report reportOpen={reportOpen} handleReportSubmit={handleReportSubmit} handleClose={handleClose}/>
)}
</div>
);
Expand Down
16 changes: 3 additions & 13 deletions src/main/web/src/scenes/Post/PostDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,14 @@ export const PostDetail: React.FC<PostDetailModel> = (props: PostDetailModel) =>
};

const [reportOpen, setReportOpen] = useState(false);
const [reportReason, setReportReason] = useState('');
const [reportDescription, setReportDescription] = useState('');

const handleReportClick = (): void => {
setReportOpen(true);
};

const handleReportSubmit = (): void => {
sendReportToBackend(reportReason, reportDescription, id, accountId, "post");
const handleReportSubmit = (reason: string, description: string): void => {
sendReportToBackend(reason, description, id, accountId, "post");
setReportOpen(!reportOpen);
setReportReason('');
setReportDescription('');
};

useEffect((): void => {
Expand Down Expand Up @@ -218,13 +214,7 @@ export const PostDetail: React.FC<PostDetailModel> = (props: PostDetailModel) =>
)}
{reportOpen && (
<div className="post-detail-report-window">
<Report
reportOpen={reportOpen}
setReportReason={setReportReason}
setReportDescription={setReportDescription}
handleReportSubmit={handleReportSubmit}
handleClose={handleClose}
/>
<Report reportOpen={reportOpen} handleReportSubmit={handleReportSubmit} handleClose={handleClose}/>
</div>
)}
</div>
Expand Down

0 comments on commit 0d5cfb7

Please sign in to comment.