From 2a7b147ece5a3cab3b985c4271246b534b92ee08 Mon Sep 17 00:00:00 2001 From: totregex Date: Mon, 6 Jan 2025 13:18:28 +0530 Subject: [PATCH 1/2] modify and use `UserStatusIndicator` --- public/locale/en.json | 2 + public/locale/hi.json | 6 +- public/locale/kn.json | 6 +- public/locale/ml.json | 6 +- public/locale/mr.json | 4 +- public/locale/ta.json | 6 +- src/components/Users/UserBanner.tsx | 1 - src/components/Users/UserListAndCard.tsx | 90 +++++++++---------- .../FacilityOrganizationUsers.tsx | 20 ++--- .../components/EditFacilityUserRoleSheet.tsx | 10 +-- src/pages/Organization/OrganizationUsers.tsx | 13 +-- 11 files changed, 73 insertions(+), 91 deletions(-) diff --git a/public/locale/en.json b/public/locale/en.json index 53586b56e86..921d3ace2cd 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -1199,6 +1199,7 @@ "nationality": "Nationality", "nearby_facilities": "Nearby Facilities", "never": "never", + "never_logged_in": "never logged in", "new_password": "New Password", "new_password_confirmation": "Confirm New Password", "new_password_same_as_old": "New password is same as old password, please enter a different new password.", @@ -1287,6 +1288,7 @@ "on": "on", "on_emergency_basis": " on emergency basis", "ongoing_medications": "Ongoing Medications", + "online": "online", "only_indian_mobile_numbers_supported": "Currently only Indian numbers are supported", "op_encounter": "OP Encounter", "op_file_closed": "OP file closed", diff --git a/public/locale/hi.json b/public/locale/hi.json index af909237150..68c91d4ad47 100644 --- a/public/locale/hi.json +++ b/public/locale/hi.json @@ -807,5 +807,7 @@ "yet_to_be_decided": "अभी निर्णय होना बाकी", "you_need_at_least_a_location_to_create_an_assest": "संपत्ति बनाने के लिए आपको कम से कम एक स्थान की आवश्यकता होगी।", "zoom_in": "ज़ूम इन", - "zoom_out": "ज़ूम आउट" -} \ No newline at end of file + "zoom_out": "ज़ूम आउट", + "never_logged_in": "कभी लॉग इन नहीं किया", + "online": "ऑनलाइन" +} diff --git a/public/locale/kn.json b/public/locale/kn.json index c605b382597..e0a84243d19 100644 --- a/public/locale/kn.json +++ b/public/locale/kn.json @@ -808,5 +808,7 @@ "yet_to_be_decided": "ಇನ್ನೂ ನಿರ್ಧರಿಸಬೇಕಿದೆ", "you_need_at_least_a_location_to_create_an_assest": "ಆಸ್ತಿಯನ್ನು ರಚಿಸಲು ನಿಮಗೆ ಕನಿಷ್ಠ ಸ್ಥಳದ ಅಗತ್ಯವಿದೆ.", "zoom_in": "ಜೂಮ್ ಇನ್", - "zoom_out": "ಜೂಮ್ ಔಟ್" -} \ No newline at end of file + "zoom_out": "ಜೂಮ್ ಔಟ್", + "never_logged_in": "ಎಂದಿಗೂ ಲಾಗ್ ಇನ್ ಆಗಿಲ್ಲ", + "online": "ಆನ್ಲೈನ್" +} diff --git a/public/locale/ml.json b/public/locale/ml.json index b7b94e00e99..abad1060f9b 100644 --- a/public/locale/ml.json +++ b/public/locale/ml.json @@ -808,5 +808,7 @@ "yet_to_be_decided": "ഇനിയും തീരുമാനമായിട്ടില്ല", "you_need_at_least_a_location_to_create_an_assest": "ഒരു അസസ്‌റ്റ് സൃഷ്‌ടിക്കാൻ നിങ്ങൾക്ക് ഒരു ലൊക്കേഷനെങ്കിലും ആവശ്യമാണ്.", "zoom_in": "സൂം ഇൻ ചെയ്യുക", - "zoom_out": "സൂം ഔട്ട്" -} \ No newline at end of file + "zoom_out": "സൂം ഔട്ട്", + "never_logged_in": "ഒരിക്കലും ലോഗിൻ ചെയ്തിട്ടില്ല", + "online": "ഓൺലൈൻ" +} diff --git a/public/locale/mr.json b/public/locale/mr.json index 3d7890fe9b9..fca0105f3e2 100644 --- a/public/locale/mr.json +++ b/public/locale/mr.json @@ -93,5 +93,7 @@ "present_health": "सध्याचे आरोग्य", "ongoing_medications": "चालू औषधे", "allergies": "अॅलर्जी", - "is_pregnant": "गर्भवती आहे" + "is_pregnant": "गर्भवती आहे", + "never_logged_in": "कधीही लॉग इन केले नाही", + "online": "ऑनलाइन" } diff --git a/public/locale/ta.json b/public/locale/ta.json index cead86d1e54..101b35a26bd 100644 --- a/public/locale/ta.json +++ b/public/locale/ta.json @@ -807,5 +807,7 @@ "yet_to_be_decided": "இன்னும் முடிவு செய்யப்படவில்லை", "you_need_at_least_a_location_to_create_an_assest": "ஒரு அசெஸ்ட்டை உருவாக்க குறைந்தபட்சம் ஒரு இருப்பிடமாவது தேவை.", "zoom_in": "பெரிதாக்கவும்", - "zoom_out": "பெரிதாக்கவும்" -} \ No newline at end of file + "zoom_out": "பெரிதாக்கவும்", + "never_logged_in": "உள்நுழைந்ததில்லை", + "online": "ஆன்லைன்" +} diff --git a/src/components/Users/UserBanner.tsx b/src/components/Users/UserBanner.tsx index f48388f8540..6f3f3bc617f 100644 --- a/src/components/Users/UserBanner.tsx +++ b/src/components/Users/UserBanner.tsx @@ -28,7 +28,6 @@ export default function UserBanner({ userData }: { userData: UserBase }) { - { @@ -65,11 +63,7 @@ const GetDetailsButton = (username: string) => { ); }; -const getNameAndStatusCard = ( - user: UserBase, - cur_online: boolean, - showDetailsButton = false, -) => { +const getNameAndStatusCard = (user: UserBase, showDetailsButton = false) => { return (
@@ -78,14 +72,7 @@ const getNameAndStatusCard = (

{formatName(user)}

-
- -
+
{ const authUser = useAuthUser(); const isAuthUser = user.id === authUser.external_id; - const isOnline = isUserOnline(user) || isAuthUser; const { t } = useTranslation(); return ( -
- - - {isOnline - ? t("online") - : user.last_login - ? relativeTime(user.last_login) - : t("never")} - -
+ {isUserOnline(user) || isAuthUser ? ( + + + {t("online")} + + ) : user.last_login ? ( + + + + last seen{" "} + {(() => { + const diffInMinutes = dayjs().diff(user.last_login, "minutes"); + const diffInHours = dayjs().diff(user.last_login, "hours"); + const diffInDays = dayjs().diff(user.last_login, "days"); + + if (diffInMinutes < 60) { + return `${diffInMinutes} minutes ago`; + } else if (diffInHours < 24) { + return `${diffInHours} hour${diffInHours > 1 ? "s" : ""} ago`; + } else { + return `${diffInDays} days ago`; + } + })()} + + + ) : ( + + + {t("never_logged_in")} + + )} +
); }; const UserCard = ({ user }: { user: UserBase }) => { @@ -173,7 +167,7 @@ const UserCard = ({ user }: { user: UserBase }) => {
{!isMediumScreen && - getNameAndStatusCard(user, userOnline, !isLessThanXLargeScreen)} + getNameAndStatusCard(user, !isLessThanXLargeScreen)}
{t("role")}
diff --git a/src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx b/src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx index 66daaa42b55..dc8ad0495bb 100644 --- a/src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx +++ b/src/pages/FacilityOrganization/FacilityOrganizationUsers.tsx @@ -3,11 +3,11 @@ import { useQueryParams } from "raviger"; import CareIcon from "@/CAREUI/icons/CareIcon"; -import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Avatar } from "@/components/Common/Avatar"; +import { UserStatusIndicator } from "@/components/Users/UserListAndCard"; import routes from "@/Utils/request/api"; import query from "@/Utils/request/query"; @@ -117,20 +117,10 @@ export default function FacilityOrganizationUsers({ id, facilityId }: Props) {

{userRole.user.first_name} {userRole.user.last_name}

-
- - {userRole.user.username} - - - - - online - - -
+ + {userRole.user.username} + +
diff --git a/src/pages/FacilityOrganization/components/EditFacilityUserRoleSheet.tsx b/src/pages/FacilityOrganization/components/EditFacilityUserRoleSheet.tsx index 39fb57115d2..c6c28b6470d 100644 --- a/src/pages/FacilityOrganization/components/EditFacilityUserRoleSheet.tsx +++ b/src/pages/FacilityOrganization/components/EditFacilityUserRoleSheet.tsx @@ -31,6 +31,7 @@ import { } from "@/components/ui/sheet"; import { Avatar } from "@/components/Common/Avatar"; +import { UserStatusIndicator } from "@/components/Users/UserListAndCard"; import routes from "@/Utils/request/api"; import mutate from "@/Utils/request/mutate"; @@ -161,16 +162,11 @@ export default function EditUserRoleSheet({

{userRole.role.name}

- Last Login -

- {userRole.user.last_login - ? new Date(userRole.user.last_login).toLocaleDateString() - : "Never"} -

+ Last Login +
-