ISSUE 8: add API logic for archiving and unarchiving a room
This commit is contained in:
@@ -382,16 +382,96 @@ const MessagesPage = () => {
|
||||
|
||||
async function archiveRoom(id) {
|
||||
sdk.setTable("room");
|
||||
// call API - callRestAPI (You can see callRestAPI implementation in other functions) here to archive room chat. Method is PUT
|
||||
// update archived state of selected room chat without refreshing the page and toast a success message
|
||||
//Also switch to the archive tab on success of the API, with the archived room chat showing under there
|
||||
try {
|
||||
const result = await sdk.callRestAPI(
|
||||
{ id, is_archive: ARCHIVE_STATUS.IS_ARCHIVE },
|
||||
"PUT"
|
||||
);
|
||||
if (!result.error) {
|
||||
// Update the room in the local state
|
||||
setRooms((prev) =>
|
||||
prev.map((room) =>
|
||||
room.id === id
|
||||
? { ...room, is_archive: ARCHIVE_STATUS.IS_ARCHIVE }
|
||||
: room
|
||||
)
|
||||
);
|
||||
// Switch to archive tab and show the archived room
|
||||
setSearchParams((params) => {
|
||||
params.set("message_tab", "archive");
|
||||
return params;
|
||||
});
|
||||
showToast(
|
||||
globalDispatch,
|
||||
"Chat archived successfully!",
|
||||
4000,
|
||||
"SUCCESS"
|
||||
);
|
||||
// Optionally, refresh archived rooms list
|
||||
getArchivedRooms();
|
||||
} else {
|
||||
showToast(
|
||||
globalDispatch,
|
||||
result.message || "Failed to archive chat.",
|
||||
4000,
|
||||
"ERROR"
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast(
|
||||
globalDispatch,
|
||||
err.message || "Failed to archive chat.",
|
||||
4000,
|
||||
"ERROR"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function unArchiveRoom(id) {
|
||||
sdk.setTable("room");
|
||||
// call API - callRestAPI (You can see callRestAPI implementation in other functions) here to unarchive room chat. Method is PUT
|
||||
// update unarchived state of selected room chat without refreshing the page and toast a success message
|
||||
//Also switch to the inbox tab on success of the API, with the unarchived room chat showing under there
|
||||
try {
|
||||
const result = await sdk.callRestAPI(
|
||||
{ id, is_archive: ARCHIVE_STATUS.NOT_ARCHIVE },
|
||||
"PUT"
|
||||
);
|
||||
if (!result.error) {
|
||||
// Update the room in the local state
|
||||
setRooms((prev) =>
|
||||
prev.map((room) =>
|
||||
room.id === id
|
||||
? { ...room, is_archive: ARCHIVE_STATUS.NOT_ARCHIVE }
|
||||
: room
|
||||
)
|
||||
);
|
||||
// Switch to inbox tab and show the unarchived room
|
||||
setSearchParams((params) => {
|
||||
params.set("message_tab", "inbox");
|
||||
return params;
|
||||
});
|
||||
showToast(
|
||||
globalDispatch,
|
||||
"Chat unarchived successfully!",
|
||||
4000,
|
||||
"SUCCESS"
|
||||
);
|
||||
// Optionally, refresh rooms list
|
||||
getRooms();
|
||||
} else {
|
||||
showToast(
|
||||
globalDispatch,
|
||||
result.message || "Failed to unarchive chat.",
|
||||
4000,
|
||||
"ERROR"
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast(
|
||||
globalDispatch,
|
||||
err.message || "Failed to unarchive chat.",
|
||||
4000,
|
||||
"ERROR"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchExtraBookingDetails() {
|
||||
@@ -782,7 +862,7 @@ const MessagesPage = () => {
|
||||
setSearchParams(searchParams);
|
||||
}}
|
||||
>
|
||||
Archive
|
||||
Archive ({archivedCount})
|
||||
</button>
|
||||
</div>
|
||||
{roomsFetched && (
|
||||
|
||||
Reference in New Issue
Block a user