Skip to content

Commit ce43fcd

Browse files
authored
fix: improvements to session list on profile page (#1258)
* fix/improvments for session list Signed-off-by: sujitaw <[email protected]> * fix/ellipse comments Signed-off-by: sujitaw <[email protected]> * fix/css improvements Signed-off-by: sujitaw <[email protected]> * fix/ svg shift to svgs directory Signed-off-by: sujitaw <[email protected]> --------- Signed-off-by: sujitaw <[email protected]>
1 parent c72d44c commit ce43fcd

File tree

4 files changed

+106
-75
lines changed

4 files changed

+106
-75
lines changed

src/components/confirmation-modal.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import React, { type ReactElement } from 'react'
1111
import { AlertComponent } from '@/components/AlertComponent'
1212
import { Button } from '@/components/ui/button'
13+
import { ConfirmationModalDefaultLogo } from '@/config/svgs/confirmationModal'
1314

1415
interface IProps {
1516
openModal: boolean
@@ -24,6 +25,7 @@ interface IProps {
2425
buttonTitles: string[]
2526
loading: boolean
2627
warning?: string
28+
image?: React.JSX.Element
2729
}
2830

2931
const ConfirmationModal = ({
@@ -39,6 +41,7 @@ const ConfirmationModal = ({
3941
buttonTitles,
4042
loading,
4143
warning,
44+
image,
4245
}: IProps): React.JSX.Element => (
4346
<Dialog open={openModal} onOpenChange={(open) => closeModal(!open)}>
4447
<DialogTitle></DialogTitle>
@@ -84,27 +87,7 @@ const ConfirmationModal = ({
8487
)}
8588
</div>
8689
<div className="p-6 text-center">
87-
<svg
88-
xmlns="http://www.w3.org/2000/svg"
89-
width="22"
90-
height="22"
91-
fill="none"
92-
viewBox="0 0 22 22"
93-
className="text-primary mx-auto mb-4 h-12 w-12"
94-
>
95-
<path
96-
fill="currentColor"
97-
d="M12.388 21.99c-.916.01-1.82.01-2.743.01-.202-.078-.397-.052-.586-.069-.685-.062-1.33-.274-1.968-.508a10.64 10.64 0 0 1-3.424-2.051 11.243 11.243 0 0 1-2.35-2.88 11.537 11.537 0 0 1-1.17-3.012c-.085-.356-.07-.721-.137-1.092C0 11.458 0 10.54 0 9.602.083 9.396.049 9.194.072 9c.088-.73.318-1.423.58-2.105A10.541 10.541 0 0 1 2.64 3.654C4.245 1.857 6.22.664 8.581.134 8.916.057 9.26.072 9.612.01 10.528 0 11.432 0 12.355 0c.216.08.425.046.627.07.739.086 1.438.318 2.126.584a10.554 10.554 0 0 1 3.24 1.987c1.804 1.611 2.994 3.594 3.524 5.962.073.328.057.666.118 1.01.01.915.01 1.819.01 2.742-.08.216-.046.425-.07.627-.086.739-.318 1.438-.584 2.126a10.544 10.544 0 0 1-1.988 3.24c-1.61 1.803-3.592 2.996-5.961 3.524-.328.073-.666.057-1.01.118Z"
98-
/>
99-
<path
100-
fill="#FFFfFf"
101-
d="M12.72 7.183c-.052 1.824-.107 3.62-.155 5.418-.033 1.232-.7 2.147-1.573 2.141-.825-.005-1.506-.88-1.543-2.024a1052 1052 0 0 1-.206-7.108c-.03-1.213.66-2.187 1.546-2.203.23-.005.461-.029.691.033.78.21 1.304 1.09 1.285 2.175-.009.513-.028 1.026-.044 1.568Z"
102-
/>
103-
<path
104-
fill="#FFF"
105-
d="M9.989 15.875c1.013-.78 2.34-.282 2.54.94.133.817-.438 1.586-1.29 1.736-.785.138-1.588-.419-1.738-1.208-.108-.572.056-1.057.488-1.468Z"
106-
/>
107-
</svg>
90+
{image ? image : <ConfirmationModalDefaultLogo />}
10891
<h3 className="text-muted-foreground mb-4 py-2 text-lg font-normal">
10992
{message}
11093
</h3>

src/config/svgs/Auth.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,27 @@ export const Icons = {
2323
</svg>
2424
),
2525
}
26+
27+
export const DestructiveConfirmation = (): JSX.Element => (
28+
<svg
29+
xmlns="http://www.w3.org/2000/svg"
30+
width="22"
31+
height="22"
32+
fill="none"
33+
viewBox="0 0 22 22"
34+
className="text-destructive mx-auto mb-4 h-12 w-12"
35+
>
36+
<path
37+
fill="currentColor"
38+
d="M12.388 21.99c-.916.01-1.82.01-2.743.01-.202-.078-.397-.052-.586-.069-.685-.062-1.33-.274-1.968-.508a10.64 10.64 0 0 1-3.424-2.051 11.243 11.243 0 0 1-2.35-2.88 11.537 11.537 0 0 1-1.17-3.012c-.085-.356-.07-.721-.137-1.092C0 11.458 0 10.54 0 9.602.083 9.396.049 9.194.072 9c.088-.73.318-1.423.58-2.105A10.541 10.541 0 0 1 2.64 3.654C4.245 1.857 6.22.664 8.581.134 8.916.057 9.26.072 9.612.01 10.528 0 11.432 0 12.355 0c.216.08.425.046.627.07.739.086 1.438.318 2.126.584a10.554 10.554 0 0 1 3.24 1.987c1.804 1.611 2.994 3.594 3.524 5.962.073.328.057.666.118 1.01.01.915.01 1.819.01 2.742-.08.216-.046.425-.07.627-.086.739-.318 1.438-.584 2.126a10.544 10.544 0 0 1-1.988 3.24c-1.61 1.803-3.592 2.996-5.961 3.524-.328.073-.666.057-1.01.118Z"
39+
/>
40+
<path
41+
fill="#FFFFFF"
42+
d="M12.72 7.183c-.052 1.824-.107 3.62-.155 5.418-.033 1.232-.7 2.147-1.573 2.141-.825-.005-1.506-.88-1.543-2.024a1052 1052 0 0 1-.206-7.108c-.03-1.213.66-2.187 1.546-2.203.23-.005.461-.029.691.033.78.21 1.304 1.09 1.285 2.175-.009.513-.028 1.026-.044 1.568Z"
43+
/>
44+
<path
45+
fill="#FFF"
46+
d="M9.989 15.875c1.013-.78 2.34-.282 2.54.94.133.817-.438 1.586-1.29 1.736-.785.138-1.588-.419-1.738-1.208-.108-.572.056-1.057.488-1.468Z"
47+
/>
48+
</svg>
49+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { JSX } from 'react'
2+
3+
export const ConfirmationModalDefaultLogo = (): JSX.Element => (
4+
<svg
5+
xmlns="http://www.w3.org/2000/svg"
6+
width="22"
7+
height="22"
8+
fill="none"
9+
viewBox="0 0 22 22"
10+
className="text-primary mx-auto mb-4 h-12 w-12"
11+
>
12+
<path
13+
fill="currentColor"
14+
d="M12.388 21.99c-.916.01-1.82.01-2.743.01-.202-.078-.397-.052-.586-.069-.685-.062-1.33-.274-1.968-.508a10.64 10.64 0 0 1-3.424-2.051 11.243 11.243 0 0 1-2.35-2.88 11.537 11.537 0 0 1-1.17-3.012c-.085-.356-.07-.721-.137-1.092C0 11.458 0 10.54 0 9.602.083 9.396.049 9.194.072 9c.088-.73.318-1.423.58-2.105A10.541 10.541 0 0 1 2.64 3.654C4.245 1.857 6.22.664 8.581.134 8.916.057 9.26.072 9.612.01 10.528 0 11.432 0 12.355 0c.216.08.425.046.627.07.739.086 1.438.318 2.126.584a10.554 10.554 0 0 1 3.24 1.987c1.804 1.611 2.994 3.594 3.524 5.962.073.328.057.666.118 1.01.01.915.01 1.819.01 2.742-.08.216-.046.425-.07.627-.086.739-.318 1.438-.584 2.126a10.544 10.544 0 0 1-1.988 3.24c-1.61 1.803-3.592 2.996-5.961 3.524-.328.073-.666.057-1.01.118Z"
15+
/>
16+
<path
17+
fill="#FFFFFF"
18+
d="M12.72 7.183c-.052 1.824-.107 3.62-.155 5.418-.033 1.232-.7 2.147-1.573 2.141-.825-.005-1.506-.88-1.543-2.024a1052 1052 0 0 1-.206-7.108c-.03-1.213.66-2.187 1.546-2.203.23-.005.461-.029.691.033.78.21 1.304 1.09 1.285 2.175-.009.513-.028 1.026-.044 1.568Z"
19+
/>
20+
<path
21+
fill="#FFF"
22+
d="M9.989 15.875c1.013-.78 2.34-.282 2.54.94.133.817-.438 1.586-1.29 1.736-.785.138-1.588-.419-1.738-1.208-.108-.572.056-1.057.488-1.468Z"
23+
/>
24+
</svg>
25+
)

src/features/profile/components/Sessions.tsx

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Badge } from '@/components/ui/badge'
1010
import { Button } from '@/components/ui/button'
1111
import ConfirmationModal from '@/components/confirmation-modal'
1212
import { DeleteIcon } from '@/config/svgs/DeleteIcon'
13+
import { DestructiveConfirmation } from '@/config/svgs/Auth'
1314
import Loader from '@/components/Loader'
1415
import { RootState } from '@/lib/store'
1516
import { SESSION_TYPE } from '@/components/types/Sessions'
@@ -18,7 +19,6 @@ import { useAppSelector } from '@/lib/hooks'
1819

1920
function Sessions(): JSX.Element {
2021
const [loading, setLoading] = useState(true)
21-
const [showDetails, setShowDetails] = useState<string>('')
2222
const [sessions, setSessions] = useState<Session[]>()
2323
const [error, setError] = useState<string | null>(null)
2424
const [success, setSuccess] = useState<string | null>(null)
@@ -43,7 +43,19 @@ function Sessions(): JSX.Element {
4343
typeof response !== 'string' &&
4444
response?.data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS
4545
) {
46-
setSessions(response.data.data)
46+
const sortByDate = response.data.data
47+
.sort(
48+
(a: Session, b: Session) =>
49+
new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
50+
)
51+
.filter((session: Session) => session.id !== currentSession)
52+
const activeSession = response.data.data.filter(
53+
(session: Session) => session.id === currentSession,
54+
)
55+
if (activeSession.length > 0) {
56+
sortByDate.unshift(...activeSession)
57+
}
58+
setSessions(sortByDate)
4759
}
4860
} catch (error) {
4961
console.error('Error fetching user sessions:', error)
@@ -158,14 +170,15 @@ function Sessions(): JSX.Element {
158170
openModal={showConfirmation}
159171
closeModal={() => setShowConfirmation(false)}
160172
onSuccess={handleDelete}
161-
message={'This Session will be Deleted Permanently.'}
173+
message={'This session will be deleted permanently.'}
162174
buttonTitles={[
163175
confirmationMessages.cancelConfirmation,
164176
confirmationMessages.sureConfirmation,
165177
]}
166178
isProcessing={loading}
167179
setFailure={setError}
168180
setSuccess={setSuccess}
181+
image={<DestructiveConfirmation />}
169182
/>
170183
{sessions &&
171184
Array.isArray(sessions) &&
@@ -177,10 +190,10 @@ function Sessions(): JSX.Element {
177190
return (
178191
<div
179192
key={record?.id}
180-
className="mt-2 rounded-md border p-4 md:flex-row"
193+
className="mt-2 h-auto rounded-md border p-4 md:flex-row"
181194
>
182-
<div className="flex flex-col items-center justify-between md:flex-row">
183-
<div className="flex items-center gap-4">
195+
<div className="flex h-full cursor-default flex-wrap items-center justify-between">
196+
<div className="flex min-w-[300px] items-center gap-4">
184197
<div className="px-2">
185198
{clientInfo ? (
186199
getSessionIcon(record, clientInfo)
@@ -194,9 +207,9 @@ function Sessions(): JSX.Element {
194207
</div>
195208
<div>
196209
{clientInfo?.ip && (
197-
<div>
210+
<div className="font-mono text-sm font-semibold">
198211
IP:{' '}
199-
<span className="text-muted-foreground break-all">
212+
<span className="break-all">
200213
{clientInfo?.ip ?? 'Not Available'}
201214
</span>
202215
</div>
@@ -223,8 +236,38 @@ function Sessions(): JSX.Element {
223236
</div>
224237
</div>
225238
</div>
239+
{clientInfo &&
240+
clientInfo?.ip &&
241+
record.sessionType !== SESSION_TYPE.ORGANIZATION && (
242+
<div
243+
className={
244+
'grid h-auto w-[250px] items-center justify-start overflow-hidden rounded-md p-4 pl-20 text-sm transition-all duration-500 lg:pl-4'
245+
}
246+
>
247+
<div className="flex justify-start">
248+
<dt>Browser :&nbsp;</dt>
249+
<dd className="text-muted-foreground">
250+
{clientInfo?.browser}
251+
</dd>
252+
</div>
253+
<div className="flex justify-start">
254+
<dt>OS :&nbsp;</dt>
255+
<dd className="text-muted-foreground">
256+
{clientInfo?.os}
257+
</dd>
258+
</div>
259+
<div className="flex justify-start">
260+
<dt>Device :&nbsp;</dt>
261+
<dd className="text-muted-foreground">
262+
{clientInfo?.deviceType}
263+
</dd>
264+
</div>
265+
</div>
266+
)}
226267
<div
227-
className={`sm:w-0.5/3 flex h-[100px] items-center ${record.sessionType !== SESSION_TYPE.ORGANIZATION && clientInfo?.ip && 'pt-10'}`}
268+
className={
269+
'flex h-[50px] grow items-center justify-end md:w-[130px] lg:grow-0'
270+
}
228271
>
229272
{record?.id === currentSession ? (
230273
<Badge className="success-alert rounded-full p-1 px-3">
@@ -242,58 +285,14 @@ function Sessions(): JSX.Element {
242285
setShowConfirmation(true)
243286
setDeletionId(record.id)
244287
}}
245-
className="flex justify-end bg-transparent p-0 shadow-none hover:bg-transparent focus:ring-0"
288+
className="flex justify-end bg-transparent p-0 px-3 shadow-none hover:bg-transparent focus:ring-0"
246289
>
247290
<DeleteIcon />
248291
</Button>
249292
</div>
250293
)}
251294
</div>
252295
</div>
253-
254-
{clientInfo?.ip &&
255-
record.sessionType !== SESSION_TYPE.ORGANIZATION && (
256-
<Button
257-
onClick={() => {
258-
setShowDetails((prev) => {
259-
if (record.id === prev) {
260-
return ''
261-
}
262-
return record.id
263-
})
264-
}}
265-
variant={'secondary'}
266-
className="mt-2 h-[30px] px-2"
267-
>
268-
{showDetails === record.id
269-
? 'Hide Details'
270-
: 'Show Details'}
271-
</Button>
272-
)}
273-
{clientInfo && (
274-
<div
275-
className={`${showDetails === record.id ? 'mt-6 h-auto rounded-md border p-4' : ''} mt-2 flex h-[0px] items-center justify-between overflow-hidden text-sm transition-all duration-500`}
276-
>
277-
<div className="grid justify-center">
278-
<dt>Browser</dt>
279-
<dd className="text-muted-foreground">
280-
{clientInfo?.browser}
281-
</dd>
282-
</div>
283-
<div className="grid justify-center">
284-
<dt>OS</dt>
285-
<dd className="text-muted-foreground">
286-
{clientInfo?.os}
287-
</dd>
288-
</div>
289-
<div className="grid justify-center">
290-
<dt>Device</dt>
291-
<dd className="text-muted-foreground">
292-
{clientInfo?.deviceType}
293-
</dd>
294-
</div>
295-
</div>
296-
)}
297296
</div>
298297
)
299298
})}

0 commit comments

Comments
 (0)