login time
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { View, Text } from "react-native";
|
||||
|
||||
import { UserLoginLog } from "@/store/api/usersApi";
|
||||
import { formatDate, formatTimeWithSeconds } from "@/utils/dateUtils";
|
||||
import { reasonLabel } from "@/utils/loginUtils";
|
||||
|
||||
interface LoginListItemProps {
|
||||
log: UserLoginLog;
|
||||
}
|
||||
|
||||
export const LoginListItem = ({ log }: LoginListItemProps) => {
|
||||
const isSuccess = log.status === "SUCCESS";
|
||||
const isFailure = log.status === "FAILURE";
|
||||
|
||||
return (
|
||||
<View className="bg-white rounded-lg p-1 mb-3 shadow-sm">
|
||||
<View className="flex-row items-center">
|
||||
<Text
|
||||
className="text-sm font-medium text-gray-700 flex-1"
|
||||
numberOfLines={1}
|
||||
ellipsizeMode="tail"
|
||||
>
|
||||
{formatDate(log.lastLoginAt)} -{" "}
|
||||
{formatTimeWithSeconds(log.lastLoginAt)} {" | "}
|
||||
<Text
|
||||
style={{
|
||||
color: isSuccess ? "#22C927" : "#F83434",
|
||||
fontWeight: "bold",
|
||||
}}
|
||||
>
|
||||
{isSuccess
|
||||
? log.activity
|
||||
: reasonLabel(log.failureReason) || "Failed"}
|
||||
</Text>
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
@@ -1,16 +1,37 @@
|
||||
import { View, Text } from "react-native";
|
||||
|
||||
import { User } from "@/store/models/User.model";
|
||||
import { useGetUserLogsByIdQuery } from "@/store/api/usersApi";
|
||||
import { LoginListItem } from "@/components/features/accounts/LoginListItem";
|
||||
|
||||
interface PersonalLoginListProps {
|
||||
user: User;
|
||||
}
|
||||
|
||||
export const PersonalLoginList = ({ user }: PersonalLoginListProps) => {
|
||||
const { data, isLoading, isError } = useGetUserLogsByIdQuery(
|
||||
{ userId: user.id, page: 1, limit: 10 },
|
||||
{ skip: !user?.id }
|
||||
);
|
||||
|
||||
const items = data?.items ?? [];
|
||||
|
||||
return (
|
||||
<View className="bg-lightGray rounded-md">
|
||||
<Text className="font-medium my-4 text-gray-600">Log-in List:</Text>
|
||||
<Text className="font-medium text-black">No logins assigned</Text>
|
||||
<Text className="font-medium mb-4 mt-0 text-gray-600">Log-in List:</Text>
|
||||
{isLoading ? (
|
||||
<Text className="text-black">Loading...</Text>
|
||||
) : isError ? (
|
||||
<Text className="text-black">-</Text>
|
||||
) : items.length === 0 ? (
|
||||
<Text className="font-medium text-black">No logins history</Text>
|
||||
) : (
|
||||
<View style={{ gap: 8 }}>
|
||||
{items.map((log, idx) => (
|
||||
<LoginListItem key={`${log.id}-${idx}`} log={log} />
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ import { InfoRow } from "./InfoRow";
|
||||
import { useAppSelector } from "@/store/hooks";
|
||||
import { selectIsMobile } from "@/store/screen/screenSizeSlice";
|
||||
import { useGetUserLogsQuery } from "@/store/api/usersApi";
|
||||
import { formatDate, formatTime } from "@/utils/dateUtils";
|
||||
import { formatDate, formatTimeWithSeconds } from "@/utils/dateUtils";
|
||||
import { RiskIndicator } from "@/components/ui/RiskIndicator";
|
||||
import { SizeEnum } from "@/constants/sizeEnum";
|
||||
import { RiskEnum, RiskLabels } from "@/constants/riskEnum";
|
||||
@@ -35,7 +35,7 @@ export const PersonalMetrics = ({ user }: PersonalMetricsProps) => {
|
||||
: logsError
|
||||
? "-"
|
||||
: lastLoginAt
|
||||
? `${formatDate(lastLoginAt)} ${formatTime(lastLoginAt)}`
|
||||
? `${formatDate(lastLoginAt)} ${formatTimeWithSeconds(lastLoginAt)}`
|
||||
: "-";
|
||||
|
||||
const lastPasswordChangeDisplay = logsLoading
|
||||
@@ -43,7 +43,7 @@ export const PersonalMetrics = ({ user }: PersonalMetricsProps) => {
|
||||
: logsError
|
||||
? "-"
|
||||
: activity === "Password reset" && lastLoginAt
|
||||
? `${formatDate(lastLoginAt)} ${formatTime(lastLoginAt)}`
|
||||
? `${formatDate(lastLoginAt)} ${formatTimeWithSeconds(lastLoginAt)}`
|
||||
: "-";
|
||||
|
||||
return (
|
||||
|
||||
@@ -23,7 +23,7 @@ export const PersonalTodoList = ({ user }: PersonalTodoListProps) => {
|
||||
|
||||
return (
|
||||
<View className="bg-lightGray rounded-md">
|
||||
<Text className="font-medium my-4 text-gray-600">To-Do List:</Text>
|
||||
<Text className="font-medium mt-0 mb-4 text-gray-600">To-Do List:</Text>
|
||||
{isLoading ? (
|
||||
<LoadingSpinner />
|
||||
) : error ? (
|
||||
|
||||
Reference in New Issue
Block a user