Skip to content

Commit

Permalink
Disallow empty notes and comments (#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 authored Jun 4, 2022
1 parent 39c9dcc commit 9f92a70
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/Components/Patient/PatientNotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ const PatientNotes = (props: PatientNotesProps) => {
const { patientId, facilityId } = props;

const dispatch: any = useDispatch();
let initialData: any = { notes: [], cPage: 1, count: 1 };
const initialData: any = { notes: [], cPage: 1, count: 1 };
const [state, setState] = useState(initialData);
const [noteField, setNoteField] = useState("");
const [isLoading, setIsLoading] = useState(true);
const [facilityName, setFacilityName] = useState("");
const [patientName, setPatientName] = useState("");

const fetchData = useCallback(
async (page: number = 1, status: statusType = { aborted: false }) => {
async (page = 1, status: statusType = { aborted: false }) => {
setIsLoading(true);
const res = await dispatch(
getPatientNotes(props.patientId, pageSize, (page - 1) * pageSize)
Expand Down Expand Up @@ -84,7 +84,13 @@ const PatientNotes = (props: PatientNotesProps) => {
const payload = {
note: noteField,
};
dispatch(addPatientNote(props.patientId, payload)).then((res: any) => {
if (!/\S+/.test(noteField)) {
Notification.Error({
msg: "Note Should Contain At Least 1 Character",
});
return;
}
dispatch(addPatientNote(props.patientId, payload)).then(() => {
Notification.Success({ msg: "Note added successfully" });
fetchData();
});
Expand Down Expand Up @@ -123,7 +129,10 @@ const PatientNotes = (props: PatientNotesProps) => {
<h3 className="text-lg">Added Notes</h3>
<div className="w-full">
{state.notes.map((note: any) => (
<div className="flex p-4 bg-white rounded-lg text-gray-800 mt-4 flex-col w-full border border-gray-300">
<div
key={note.id}
className="flex p-4 bg-white rounded-lg text-gray-800 mt-4 flex-col w-full border border-gray-300"
>
<div className="flex w-full ">
<p className="text-justify">{note.note}</p>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/Components/Resource/CommentSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ const CommentSection = (props: CommentSectionProps) => {
const payload = {
comment: commentBox,
};
if (!/\S+/.test(commentBox)) {
Notification.Error({
msg: "Comment Should Contain At Least 1 Character",
});
return;
}
dispatch(addResourceComments(props.id, payload)).then((_: any) => {
Notification.Success({ msg: "Comment added successfully" });
fetchData();
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Shifting/CommentsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const CommentSection = (props: CommentSectionProps) => {
const payload = {
comment: commentBox,
};
if (commentBox.length < 1) {
if (!/\S+/.test(commentBox)) {
Notification.Error({
msg: "Comment Should Contain At Least 1 Characters",
msg: "Comment Should Contain At Least 1 Character",
});
return;
}
Expand Down

0 comments on commit 9f92a70

Please sign in to comment.