Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(chore) Flag rules-of-hooks lint violations #1784

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"plugins": ["@typescript-eslint", "react-hooks"],
"rules": {
"react-hooks/exhaustive-deps": "warn",
"react-hooks/rules-of-hooks": "error",
// Disabling these rules for now just to keep the diff small. I'll enable them in a future PR that fixes lint issues.
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
const isTablet = useLayoutType() === 'tablet';
const isOnline = useConnectivity();
const sessionUser = useSession();
const { error: errorFetchingLocations } = isOnline ? useLocations() : { error: false };
const { error } = useLocations();
const errorFetchingLocations = isOnline ? error : false;
const sessionLocation = sessionUser?.sessionLocation;
const config = useConfig() as ChartConfig;
const [contentSwitcherIndex, setContentSwitcherIndex] = useState(config.showRecommendedVisitTypeTab ? 0 : 1);
Expand All @@ -81,7 +82,8 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
const { activePatientEnrollment, isLoading } = useActivePatientEnrollment(patientUuid);
const { mutate: mutateCurrentVisit } = useVisit(patientUuid);
const { mutateVisits } = useVisits(patientUuid);
const allVisitTypes = isOnline ? useVisitTypes() : useOfflineVisitType();
const allVisitTypes = useConditionalVisitTypes();

const { mutate } = useVisit(patientUuid);
const [errorFetchingResources, setErrorFetchingResources] = useState<{
blockSavingForm: boolean;
Expand Down Expand Up @@ -305,8 +307,7 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
})),
};
if (visitToEdit?.uuid) {
// The request throws 400 (Bad request)error when patient is passed in the update payload

// The request throws 400 (Bad request) error when patient is passed in the update payload
delete payload.patient;
}

Expand Down Expand Up @@ -682,4 +683,14 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({
);
};

function useConditionalVisitTypes() {
const isOnline = useConnectivity();

const visitTypesHook = isOnline ? useVisitTypes : useOfflineVisitType;

const allVisitTypes = visitTypesHook();

return allVisitTypes;
}

export default StartVisitForm;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { launchPatientWorkspace, useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib';
import React, { useCallback } from 'react';
import styles from './active-visit-buttons.scss';
import { useTranslation } from 'react-i18next';
import { Button, MenuButton, MenuItem } from '@carbon/react';
import { Add } from '@carbon/react/icons';
import { useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib';
import type { Visit } from '@openmrs/esm-framework';
import { showModal, useLayoutType } from '@openmrs/esm-framework';

Expand All @@ -17,6 +17,16 @@ const ActiveVisitActions: React.FC<ActiveVisitActionsInterface> = ({ visit, pati
const isTablet = layout === 'tablet';
const isMobile = layout === 'phone';

const launchAllergiesFormWorkspace = useLaunchWorkspaceRequiringVisit('patient-allergy-form-workspace');
const launchAppointmentsFormWorkspace = useLaunchWorkspaceRequiringVisit('appointments-form-workspace');
const launchClinicalFormsWorkspace = useLaunchWorkspaceRequiringVisit('clinical-forms-workspace');
const launchConditionsFormWorkspace = useLaunchWorkspaceRequiringVisit('conditions-form-workspace');
const launchOrderBasketFormWorkspace = useLaunchWorkspaceRequiringVisit('order-basket');
const launchVisitNotesFormWorkspace = useLaunchWorkspaceRequiringVisit('visit-notes-form-workspace');
const launchVitalsAndBiometricsFormWorkspace = useLaunchWorkspaceRequiringVisit(
'patient-vitals-biometrics-form-workspace',
);

return (
<div>
{isTablet || isMobile ? (
Expand All @@ -27,43 +37,43 @@ const ActiveVisitActions: React.FC<ActiveVisitActionsInterface> = ({ visit, pati
<MenuItem
kind="ghost"
label={t('addNote', 'Add note')}
onClick={useLaunchWorkspaceRequiringVisit('visit-notes-form-workspace')}
onClick={launchVisitNotesFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('addLabOrPrescription', 'Add lab or prescription')}
onClick={useLaunchWorkspaceRequiringVisit('order-basket')}
onClick={launchOrderBasketFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('addVitals', 'Add vitals')}
onClick={useLaunchWorkspaceRequiringVisit('patient-vitals-biometrics-form-workspace')}
onClick={launchVitalsAndBiometricsFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('addCondition', 'Add condition')}
onClick={useLaunchWorkspaceRequiringVisit('conditions-form-workspace')}
onClick={launchConditionsFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('addAllergy', 'Add allergy')}
onClick={useLaunchWorkspaceRequiringVisit('patient-allergy-form-workspace')}
onClick={launchAllergiesFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('addAppointment', 'Add appointment')}
onClick={useLaunchWorkspaceRequiringVisit('appointments-form-workspace')}
onClick={launchAppointmentsFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('otherForm', 'Other form')}
onClick={useLaunchWorkspaceRequiringVisit('clinical-forms-workspace')}
onClick={launchClinicalFormsWorkspace}
renderIcon={Add}
/>
</MenuButton>
Expand All @@ -74,15 +84,15 @@ const ActiveVisitActions: React.FC<ActiveVisitActionsInterface> = ({ visit, pati
kind="ghost"
renderIcon={(props) => <Add size={16} {...props} />}
iconDescription="Add visit note"
onClick={useLaunchWorkspaceRequiringVisit('visit-notes-form-workspace')}
onClick={launchVisitNotesFormWorkspace}
>
{t('addNote', 'Add note')}
</Button>
<Button
kind="ghost"
renderIcon={(props) => <Add size={16} {...props} />}
iconDescription="Add lab or prescription"
onClick={useLaunchWorkspaceRequiringVisit('order-basket')}
onClick={launchOrderBasketFormWorkspace}
>
{t('addLabOrPrescription', 'Add lab or prescription')}
</Button>
Expand All @@ -93,31 +103,31 @@ const ActiveVisitActions: React.FC<ActiveVisitActionsInterface> = ({ visit, pati
<MenuItem
kind="ghost"
label={t('addVitals', 'Add vitals')}
onClick={useLaunchWorkspaceRequiringVisit('patient-vitals-biometrics-form-workspace')}
onClick={launchVitalsAndBiometricsFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('addCondition', 'Add condition')}
onClick={useLaunchWorkspaceRequiringVisit('conditions-form-workspace')}
onClick={launchConditionsFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('addAllergy', 'Add allergy')}
onClick={useLaunchWorkspaceRequiringVisit('patient-allergy-form-workspace')}
onClick={launchAllergiesFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('addAppointment', 'Add appointment')}
onClick={useLaunchWorkspaceRequiringVisit('appointments-form-workspace')}
onClick={launchAppointmentsFormWorkspace}
renderIcon={Add}
/>
<MenuItem
kind="ghost"
label={t('otherForm', 'Other form')}
onClick={useLaunchWorkspaceRequiringVisit('clinical-forms-workspace')}
onClick={launchClinicalFormsWorkspace}
renderIcon={Add}
/>
</MenuButton>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { openmrsFetch, restBaseUrl, useAbortController } from '@openmrs/esm-framework';
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
import { type Order } from '@openmrs/esm-patient-common-lib';

export function cancelOrder(order: Order, requestBody: any) {
const ac = useAbortController();
const ac = new AbortController();

return openmrsFetch(`${restBaseUrl}/order/${order.uuid}/fulfillerdetails/`, {
method: 'POST',
Expand Down
Loading