Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kahummer committed Jul 10, 2024
1 parent 7ce4198 commit 415ab6f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {
URL_LOCATION_UNIT_EDIT,
URL_LOCATION_UNIT_ADD,
URL_LOCATION_VIEW_DETAILS,
BACK_SEARCH_PARAM,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import { Link } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';
import { useMls } from '../../mls';
import { URL_LOCATION_UNIT_EDIT, URL_SERVICE_POINT_ADD_EDIT } from '../../constants';
import {
BACK_SEARCH_PARAM,
URL_LOCATION_UNIT_EDIT,
URL_SERVICE_POINT_ADD_EDIT,
} from '../../constants';
import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation';

interface EditLinkProps {
Expand All @@ -12,10 +16,17 @@ const EditLink: React.FC<EditLinkProps> = ({ location }) => {
const { t } = useMls();
const { id, physicalType } = location;
const isBuilding = physicalType?.coding?.[0].code === 'bu';
const currentLocation = useLocation();

const backToParam = new URLSearchParams({ [BACK_SEARCH_PARAM]: currentLocation.pathname });

return (
<Link
to={`${isBuilding ? URL_SERVICE_POINT_ADD_EDIT : URL_LOCATION_UNIT_EDIT}/${id}`}
to={
isBuilding
? `${URL_SERVICE_POINT_ADD_EDIT}/${id}`
: `${URL_LOCATION_UNIT_EDIT}/${id}?${backToParam}`
}
className="m-0 p-1"
>
{t('Edit')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Alert, Button, Col, Divider, Dropdown, MenuProps, Row } from 'antd';
import {
BACK_SEARCH_PARAM,
URL_LOCATION_UNIT_ADD,
URL_LOCATION_UNIT_EDIT,
URL_LOCATION_VIEW_DETAILS,
locationResourceType,
parentIdQueryParam,
Expand Down Expand Up @@ -60,7 +59,6 @@ export const ChildLocations = ({ fhirBaseUrl, locationId }: InventoryViewProps)
type TableData = typeof tableData[0];

const backParamObj = { [BACK_SEARCH_PARAM]: location.pathname };
const backToParam = new URLSearchParams(backParamObj).toString();
const getItems = (_: TableData): MenuProps['items'] => {
// Todo: replace _ above when handling onClick
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation';
import { useMls } from '../../../mls';
import React from 'react';
import { ResourceDetails } from '@opensrp/react-utils';
import { Link, useLocation } from 'react-router-dom';
import { parseLocationDetails } from '../utils';
import { BACK_SEARCH_PARAM, URL_LOCATION_UNIT_EDIT } from '../../../constants';
import { RbacCheck } from '@opensrp/rbac';
import { EditLink } from '../../EditLink';

Expand Down Expand Up @@ -47,10 +45,6 @@ export const LocationDetails = ({ location }: { location: ILocation }) => {
administrativeLevel,
} = parseLocationDetails(location);

const loc = useLocation();
const currentPath = loc.pathname;
const backToParam = new URLSearchParams({ [BACK_SEARCH_PARAM]: currentPath }).toString();

const otherDetailsMap = {
[t('Location Name')]: name,
[t('Status')]: status,
Expand Down

0 comments on commit 415ab6f

Please sign in to comment.