Skip to content

Commit

Permalink
Merge pull request #5429 from msupply-foundation/#5428-crashing-app-w…
Browse files Browse the repository at this point in the history
…hen-switching-from-patient-to-prescriber

#5428 App crashing in dispensing mode
  • Loading branch information
sah-arjun authored Jan 17, 2024
2 parents 535348c + c24d306 commit ec5cc3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/pages/dataTableUtilities/getColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ROUTES } from '../../navigation/constants';
import { FORMS, MODALS, TABS } from '../../widgets/constants';

const PAGE_COLUMN_WIDTHS = {
[FORMS.PATIENT]: [2.5, 2, 4, 4, 2, 2, 2, 2],
[FORMS.PATIENT]: [3, 2, 4, 4, 2, 2, 1.5, 2],
[FORMS.PRESCRIBER]: [1, 3, 3, 1],
[MODALS.PATIENT_HISTORY]: [1, 4, 1, 1, 2],
[MODALS.VACCINE_HISTORY]: [1, 4, 1, 1, 2],
Expand Down
14 changes: 11 additions & 3 deletions src/reducers/DispensaryReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,31 @@ export const DispensaryReducer = (state = initialState(), action) => {
const { usingAdverseDrugReactions } = payload;
const { dataSet } = state;

// Default to patient
let sortBy = 'createdDate';
let isAscending = false;

const patientDataSet = usingAdverseDrugReactions
? 'patientWithAdverseDrugReactions'
: 'patient';

const prescriberDataSet = 'prescriber';
const newDataSet = dataSet === patientDataSet ? prescriberDataSet : patientDataSet;

const newColumns = getColumns(newDataSet);

if (newDataSet === 'prescriber') {
sortBy = 'firstName';
isAscending = true;
}

const newData = UIDatabase.objects(newDataSet === patientDataSet ? 'Patient' : 'Prescriber');

return {
...state,
dataSet: newDataSet,
columns: newColumns,
sortKey: 'createdDate',
isAscending: false,
sortKey: sortBy,
isAscending,
searchTerm: '',
data: newData,
};
Expand Down

0 comments on commit ec5cc3c

Please sign in to comment.