Skip to content

Commit

Permalink
Add support to delete location
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu1902 committed Jan 8, 2024
1 parent 37b451a commit 32d7560
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 51 deletions.
131 changes: 81 additions & 50 deletions src/Components/Facility/LocationManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import routes from "../../Redux/api";
import PaginatedList from "../../CAREUI/misc/PaginatedList";
import { LocationModel } from "./models";
import RecordMeta from "../../CAREUI/display/RecordMeta";
import request from "../../Utils/request/request";
import * as Notification from "../../Utils/Notifications.js";

const Loading = lazy(() => import("../Common/Loading"));

Expand Down Expand Up @@ -55,7 +57,7 @@ export default function LocationManagement({ facilityId }: Props) {
<Loading />
</PaginatedList.WhenLoading>
<PaginatedList.Items<LocationModel> className="my-8 grid gap-3 @4xl:grid-cols-2 @6xl:grid-cols-3 @[100rem]:grid-cols-4 lg:mx-8">
{(item) => <Location {...item} />}
{(item) => <Location {...item} facility={{ id: facilityId }} />}
</PaginatedList.Items>
</div>

Expand All @@ -73,71 +75,100 @@ const Location = ({
description,
middleware_address,
location_type,
facility,
created_date,
modified_date,
id,
}: LocationModel) => (
<div className="flex h-full w-full flex-col rounded border border-gray-300 bg-white p-6 shadow-sm transition-all duration-200 ease-in-out hover:border-primary-400">
<div className="flex-1">
<div className="flex w-full items-center justify-between gap-2">
<div className="flex items-center gap-3">
<p
className="break-words text-xl font-medium"
id="view-location-name"
>
{name}
</p>
<div
className="h-fit rounded-full border-2 border-primary-500 bg-primary-100 px-3 py-[3px]"
id="location-type"
>
<p className="text-xs font-bold text-primary-500">
{location_type}
}: LocationModel) => {
const deleteAssetLocation = async () => {
const res: any = await request(routes.deleteFacilityAssetLocation, {
pathParams: {
facility_external_id: facility?.id ?? "",
external_id: id ?? "",
},
});
if (res?.res?.status === 204) {
Notification.Success({ msg: `Location ${name} deleted succcessully` });
}
};

return (
<div className="flex h-full w-full flex-col rounded border border-gray-300 bg-white p-6 shadow-sm transition-all duration-200 ease-in-out hover:border-primary-400">
<div className="flex-1">
<div className="flex w-full items-center justify-between gap-2">
<div className="flex items-center gap-3">
<p
className="break-words text-xl font-medium"
id="view-location-name"
>
{name}
</p>
<div
className="h-fit rounded-full border-2 border-primary-500 bg-primary-100 px-3 py-[3px]"
id="location-type"
>
<p className="text-xs font-bold text-primary-500">
{location_type}
</p>
</div>
</div>
</div>
<p
className="mt-3 break-all text-sm font-medium text-gray-700"
id="view-location-description"
>
{description || "-"}
</p>
<p className="mt-3 text-sm font-semibold text-gray-700">
Middleware Address:
</p>
<p
className="mt-1 break-all font-mono text-sm font-bold text-gray-700"
id="view-location-middleware"
>
{middleware_address || "-"}
</p>
</div>

<ButtonV2
id="manage-bed-button"
variant="secondary"
border
className="mt-3 w-full"
href={`location/${id}/beds`}
>
<CareIcon className="care-l-bed text-lg" />
Manage Beds
</ButtonV2>
<div className="mt-2 flex w-full flex-col gap-2 md:flex-row">
<ButtonV2
id="edit-location-button"
variant="secondary"
border
className="md:w-full"
href={`location/${id}/update`}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon className="care-l-pen text-lg" />
Edit
</ButtonV2>
<ButtonV2
id="delete-location-button"
variant="secondary"
border
className="md:w-full"
onClick={deleteAssetLocation}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon className="care-l-trash text-lg" />
Delete
</ButtonV2>
</div>
<p
className="mt-3 break-all text-sm font-medium text-gray-700"
id="view-location-description"
>
{description || "-"}
</p>
<p className="mt-3 text-sm font-semibold text-gray-700">
Middleware Address:
</p>
<p
className="mt-1 break-all font-mono text-sm font-bold text-gray-700"
id="view-location-middleware"
>
{middleware_address || "-"}
</p>
</div>

<ButtonV2
id="manage-bed-button"
variant="secondary"
border
className="mt-3 w-full"
href={`location/${id}/beds`}
>
<CareIcon className="care-l-bed text-lg" />
Manage Beds
</ButtonV2>

<div className="mt-3 flex items-center justify-between gap-4 text-sm font-medium text-gray-700">
<RecordMeta time={created_date} prefix="Created:" />
<RecordMeta time={modified_date} prefix="Modified:" />
<div className="mt-3 flex items-center justify-between gap-4 text-sm font-medium text-gray-700">
<RecordMeta time={created_date} prefix="Created:" />
<RecordMeta time={modified_date} prefix="Modified:" />
</div>
</div>
</div>
);
);
};
3 changes: 2 additions & 1 deletion src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ export interface LocationModel {
middleware_address?: string;
location_type?: AssetLocationType;
facility?: {
name: string;
name?: string;
id?: string;
};
created_date?: string;
modified_date?: string;
Expand Down
7 changes: 7 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ const routes = {
path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/",
method: "PATCH",
},
deleteFacilityAssetLocation: {
path: "/api/v1/facility/{facility_external_id}/asset_location/{external_id}/",
method: "DELETE",
TRes: Type<null | {
detail?: string;
}>(),
},

// Asset bed
listAssetBeds: {
Expand Down

0 comments on commit 32d7560

Please sign in to comment.