mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 08:14:24 +00:00
consistent sorting
This commit is contained in:
@@ -74,6 +74,7 @@ function findValidSession(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// sort by change date descending
|
||||
validSessionsWithHint.sort((a, b) => {
|
||||
const dateA = a.changeDate ? timestampDate(a.changeDate).getTime() : 0;
|
||||
const dateB = b.changeDate ? timestampDate(b.changeDate).getTime() : 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { timestampMs } from "@zitadel/client";
|
||||
import { timestampDate } from "@zitadel/client";
|
||||
import { Session } from "@zitadel/proto/zitadel/session/v2/session_pb";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useState } from "react";
|
||||
@@ -12,14 +12,6 @@ type Props = {
|
||||
authRequestId?: string;
|
||||
};
|
||||
|
||||
function sortFc(a: Session, b: Session) {
|
||||
if (a.changeDate && b.changeDate) {
|
||||
return timestampMs(a.changeDate) - timestampMs(b.changeDate);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function SessionsList({ sessions, authRequestId }: Props) {
|
||||
const t = useTranslations("accounts");
|
||||
const [list, setList] = useState<Session[]>(sessions);
|
||||
@@ -27,7 +19,16 @@ export function SessionsList({ sessions, authRequestId }: Props) {
|
||||
<div className="flex flex-col space-y-2">
|
||||
{list
|
||||
.filter((session) => session?.factors?.user?.loginName)
|
||||
.sort(sortFc)
|
||||
// sort by change date descending
|
||||
.sort((a, b) => {
|
||||
const dateA = a.changeDate
|
||||
? timestampDate(a.changeDate).getTime()
|
||||
: 0;
|
||||
const dateB = b.changeDate
|
||||
? timestampDate(b.changeDate).getTime()
|
||||
: 0;
|
||||
return dateB - dateA;
|
||||
})
|
||||
.map((session, index) => {
|
||||
return (
|
||||
<SessionItem
|
||||
|
||||
Reference in New Issue
Block a user