Skip to content

Commit

Permalink
integrate add waiting user feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu1902 committed Nov 24, 2023
1 parent 8abb23e commit 1af45d6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
86 changes: 74 additions & 12 deletions src/Components/Facility/Consultations/LiveFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const LiveFeed = (props: any) => {

// inital lock asset status
const [lockStatus, setLockStatus] = useState(props.asset.is_locked);
const [inWaiting, setInWaiting] = useState(false);
const [lockedBy, setLockedBy] = useState(props.asset.locked_by);
setLockedBy(props.asset.locked_by);
const [user, setUser] = useState<any>({});

const { width } = useWindowDimensions();
const extremeSmallScreenBreakpoint = 320;
Expand Down Expand Up @@ -191,6 +195,13 @@ const LiveFeed = (props: any) => {
setBed(toUpdate?.bed_object);
}, [toUpdate]);

// get current user details
useEffect(async () => {
const { data } = await request(routes.currentUser, {});
setUser(data);
console.log(data);
}, []);

useEffect(() => {
getBedPresets(cameraAsset.id);
if (bedPresets?.[0]?.position) {
Expand Down Expand Up @@ -296,6 +307,36 @@ const LiveFeed = (props: any) => {
return { ...option, callback: () => cb(option) };
});

// add to waiting list method
const addToWaitingList = async () => {
const { data }: any = await request(routes.addWaitingUserToAsset, {
pathParams: {
asset_external_id: props.asset?.id ?? "",
},
});

Notification.Success({ msg: data?.message });

// dispatch(addToWaitingList(props.asset?.id)).then((res) => {
// if (!res || res.status !== 201) {
// Notification.Error({ msg: "Failed to add to waiting list" });
// } else {
// Notification.Success({ msg: "Added to waiting list" });
// }
// setLoading(undefined);
// });
};

// remove from waiting list method
const removeFromWaitingList = async () => {
const { data }: any = await request(routes.removeWaitingUserFromAsset, {
pathParams: {
asset_external_id: props.asset?.id ?? "",
},
});
Notification.Success({ msg: data?.message });
};

// lock and unlock asset methods
const lockAsset = async () => {
const { data }: any = await request(routes.lockAsset, {
Expand Down Expand Up @@ -497,18 +538,39 @@ const LiveFeed = (props: any) => {

<div className="mx-4 flex max-w-sm flex-col">
<div>
<button
onClick={() => {
if (lockStatus) {
unlockAsset();
} else {
lockAsset();
}
setLockStatus(!lockStatus);
}}
>
Lock Status: <b>{lockStatus ? "Locked" : "Unlocked"}</b>
</button>
{!lockStatus || (lockStatus && lockedBy === user?.username) ? (
<button
onClick={() => {
if (lockStatus) {
unlockAsset();
} else {
lockAsset();
}
setLockStatus(!lockStatus);
}}
>
Lock Status: <b>{lockStatus ? "Locked" : "Unlocked"}</b>
</button>
) : (
<div>
<p>Locked by: {lockedBy}</p>
<button
onClick={() => {
console.log(lockedBy);
console.log(lockStatus);
console.log(user.username);
if (inWaiting) {
removeFromWaitingList();
} else {
addToWaitingList();
}
setInWaiting(!inWaiting);
}}
>
Get {inWaiting ? "out of" : "in"} Waiting List
</button>
</div>
)}
<button>Refresh</button>
</div>
<nav className="flex flex-wrap">
Expand Down
4 changes: 4 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,14 @@ const routes = {
addWaitingUserToAsset: {
path: "/api/v1/asset/{asset_external_id}/add_waiting_user/",
method: "POST",
TRes: Type<unknown>(),
TBody: Type<unknown>(),
},
removeWaitingUserFromAsset: {
path: "/api/v1/asset/{asset_external_id}/remove_waiting_user/",
method: "POST",
TRes: Type<unknown>(),
TBody: Type<unknown>(),
},

abha: {
Expand Down

0 comments on commit 1af45d6

Please sign in to comment.