Skip to content

Commit

Permalink
refactor props
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu1902 committed Dec 13, 2023
1 parent 341fd04 commit 0c04dfe
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Components/Facility/PatientNotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import routes from "../../Redux/api";
import { PatientNotesModel } from "./models";

interface PatientNotesProps {
patientId: any;
facilityId: any;
patientId: string;
facilityId: string;
consultationId: string;
reload?: boolean;
setReload?: any;
}
Expand All @@ -22,10 +23,8 @@ interface StateType {

const pageSize = RESULTS_PER_PAGE_LIMIT;

const PatientNotesList: React.FC<
PatientNotesProps & { consultationId: string }
> = ({ consultationId, ...props }) => {
const { reload, setReload } = props;
const PatientNotesList: React.FC<PatientNotesProps> = (props) => {
const { consultationId, reload, setReload } = props;
// console.log(props);

const initialData: StateType = { notes: [], cPage: 1, totalPages: 1 };
Expand All @@ -40,17 +39,18 @@ const PatientNotesList: React.FC<
consultation: consultationId,
offset: (state.cPage - 1) * RESULTS_PER_PAGE_LIMIT,
},
prefetch: reload,
prefetch: reload && state.cPage <= state.totalPages,
onResponse: ({ res, data }) => {
setIsLoading(true);
if (res?.status === 200 && data) {
console.log(state);
if (res?.status === 200 && data && state.cPage <= state.totalPages) {
setState((prevState: any) => ({
...prevState,
notes: [...prevState.notes, ...data.results],
totalPages: Math.ceil(data.count / pageSize),
}));
setReload(false);
}
setReload(false);
setIsLoading(false);
},
});
Expand Down

0 comments on commit 0c04dfe

Please sign in to comment.