Skip to content

Commit

Permalink
Provide list id when uploading products and inventory (#1458)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki authored Aug 2, 2024
1 parent 766912c commit a4d7884
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/src/configs/dispatchConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
DEFAULTS_TABLE_PAGE_SIZE,
PRACTITIONER_TO_ORG_ASSIGNMENT_STRATEGY,
AUTHZ_STRATEGY,
COMMODITIES_LIST_RESOURCE_ID,
FHIR_INVENTORY_LIST_ID,
} from './env';
import { URL_BACKEND_LOGIN, URL_REACT_LOGIN } from '../constants';

Expand All @@ -33,6 +35,8 @@ const configObject: ConfigState = {
defaultTablesPageSize: DEFAULTS_TABLE_PAGE_SIZE,
practToOrgAssignmentStrategy: PRACTITIONER_TO_ORG_ASSIGNMENT_STRATEGY,
rbacStrategy: AUTHZ_STRATEGY,
productListId: COMMODITIES_LIST_RESOURCE_ID,
inventoryListId: FHIR_INVENTORY_LIST_ID,
};

setAllConfigs(configObject);
14 changes: 13 additions & 1 deletion packages/fhir-import/src/containers/StartImportView/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
DATA_IMPORT_LIST_URL,
IMPORT_DOMAIN_URI,
dataImportRQueryKey,
IMPORT_ENDPOINT,
} from '../../constants';
import { useTranslation } from '../../mls';
import {
Expand All @@ -28,6 +29,7 @@ import {
} from '@opensrp/notifications';
import { HTTPMethod, getDefaultHeaders } from '@opensrp/server-service';
import './form.css';
import { getAllConfigs } from '@opensrp/pkg-config';

const { Text, Title } = Typography;

Expand Down Expand Up @@ -75,10 +77,20 @@ export const DataImportForm = (props: DataImportFormProps) => {
const history = useHistory();
const { t } = useTranslation();
const goTo = (url = '#') => history.push(url);
const { productListId, inventoryListId } = getAllConfigs();
const listIdsSParams = new URLSearchParams();

if (productListId) {
listIdsSParams.append('productListId', productListId);
}
if (inventoryListId) {
listIdsSParams.append('inventoryListId', inventoryListId);
}

const { mutate, isLoading } = useMutation(
async (values: FormFields) => {
const service = new OpenSRPService('/$import', IMPORT_DOMAIN_URI, customFetchOptions);
const postUrl = `${IMPORT_ENDPOINT}?${listIdsSParams.toString()}`;
const service = new OpenSRPService(postUrl, IMPORT_DOMAIN_URI, customFetchOptions);
const formData = new FormData();

Object.entries(values).forEach(([key, value]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { store } from '@opensrp/store';
import userEvent from '@testing-library/user-event';
import * as notifications from '@opensrp/notifications';
import * as constants from '../../../constants';
import * as pkgConfig from '@opensrp/pkg-config';

jest.mock('@opensrp/pkg-config', () => ({
__esModule: true,
...Object.assign({}, jest.requireActual('@opensrp/pkg-config')),
}));

// eslint-disable-next-line @typescript-eslint/no-var-requires
const fetch = require('node-fetch');
Expand Down Expand Up @@ -77,6 +83,13 @@ test.skip('creates an import submission correctly', async () => {
.reply(200, [])
.persist();

jest.spyOn(pkgConfig, 'getAllConfigs').mockImplementation(() => {
return {
productListId: 'productListId',
inventoryListId: 'inventoryListId',
};
});

const successNoticeMock = jest
.spyOn(notifications, 'sendSuccessNotification')
.mockImplementation(() => undefined);
Expand Down
4 changes: 4 additions & 0 deletions packages/pkg-config/src/configStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface ConfigState {
defaultTablesPageSize?: number; // static value of the default number of rows per page
rbacStrategy?: KeycloakStrategies;
practToOrgAssignmentStrategy?: PractToOrgAssignmentStrategy;
productListId?: string;
inventoryListId?: string;
}

export interface UserPreference {
Expand Down Expand Up @@ -61,6 +63,8 @@ const defaultConfigs: GlobalState = {
projectCode: 'core',
rbacStrategy: 'keycloak',
practToOrgAssignmentStrategy: PractToOrgAssignmentStrategy.ONE_TO_MANY,
productListId: undefined,
inventoryListId: undefined,
};

let localstorage: UserPreference = localStorage.getItem(USER_PREFERENCE_KEY)
Expand Down

0 comments on commit a4d7884

Please sign in to comment.