diff --git a/app/src/configs/dispatchConfig.ts b/app/src/configs/dispatchConfig.ts index 6dfb0e004..d62aa52eb 100644 --- a/app/src/configs/dispatchConfig.ts +++ b/app/src/configs/dispatchConfig.ts @@ -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'; @@ -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); diff --git a/packages/fhir-import/src/containers/StartImportView/form.tsx b/packages/fhir-import/src/containers/StartImportView/form.tsx index 2fedd1a54..8a9d0bedd 100644 --- a/packages/fhir-import/src/containers/StartImportView/form.tsx +++ b/packages/fhir-import/src/containers/StartImportView/form.tsx @@ -19,6 +19,7 @@ import { DATA_IMPORT_LIST_URL, IMPORT_DOMAIN_URI, dataImportRQueryKey, + IMPORT_ENDPOINT, } from '../../constants'; import { useTranslation } from '../../mls'; import { @@ -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; @@ -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]) => { diff --git a/packages/fhir-import/src/containers/StartImportView/tests/form.test.tsx b/packages/fhir-import/src/containers/StartImportView/tests/form.test.tsx index 89515899b..07a04e18f 100644 --- a/packages/fhir-import/src/containers/StartImportView/tests/form.test.tsx +++ b/packages/fhir-import/src/containers/StartImportView/tests/form.test.tsx @@ -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'); @@ -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); diff --git a/packages/pkg-config/src/configStore/index.ts b/packages/pkg-config/src/configStore/index.ts index 282643486..4b3470e88 100644 --- a/packages/pkg-config/src/configStore/index.ts +++ b/packages/pkg-config/src/configStore/index.ts @@ -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 { @@ -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)