-
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement UI for logging out (#638)
* feat: implement UI for logging out * feat: use old style dialogs for logout confirmation * feat: implement manage sessions * feat: implement session logout success dialog * feat: use snjs alert for revoking sessions confirmation * fix: make OtherSessionsLogout easier to read
- Loading branch information
Showing
19 changed files
with
342 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ComponentChildren, FunctionComponent } from 'preact'; | ||
import { | ||
AlertDialog, | ||
AlertDialogDescription, | ||
AlertDialogLabel, | ||
} from '@reach/alert-dialog'; | ||
import { useRef } from 'preact/hooks'; | ||
|
||
export const ConfirmationDialog: FunctionComponent<{ | ||
title: string | ComponentChildren; | ||
}> = ({ title, children }) => { | ||
const ldRef = useRef<HTMLButtonElement>(); | ||
|
||
return ( | ||
<AlertDialog leastDestructiveRef={ldRef}> | ||
{/* sn-component is focusable by default, but doesn't stretch to child width | ||
resulting in a badly focused dialog. Utility classes are not available | ||
at the sn-component level, only below it. tabIndex -1 disables focus | ||
and enables it on the child component */} | ||
<div tabIndex={-1} className="sn-component"> | ||
<div | ||
tabIndex={0} | ||
className="max-w-89 bg-default rounded shadow-overlay focus:padded-ring-info px-9 py-9 flex flex-col items-center" | ||
> | ||
<AlertDialogLabel>{title}</AlertDialogLabel> | ||
<div className="min-h-2" /> | ||
|
||
<AlertDialogDescription className="flex flex-col items-center"> | ||
{children} | ||
</AlertDialogDescription> | ||
</div> | ||
</div> | ||
</AlertDialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useRef, useState } from 'preact/hooks'; | ||
import { | ||
AlertDialog, | ||
AlertDialogDescription, | ||
AlertDialogLabel, | ||
} from '@reach/alert-dialog'; | ||
import { WebApplication } from '@/ui_models/application'; | ||
import { AppState } from '@/ui_models/app_state'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { FunctionComponent } from 'preact'; | ||
|
||
type Props = { | ||
application: WebApplication; | ||
appState: AppState; | ||
}; | ||
|
||
export const OtherSessionsLogoutContainer = observer((props: Props) => { | ||
if (!props.appState.accountMenu.otherSessionsLogOut) { | ||
return null; | ||
} | ||
return <ConfirmOtherSessionsLogout {...props} />; | ||
}); | ||
|
||
const ConfirmOtherSessionsLogout = observer( | ||
({ application, appState }: Props) => { | ||
|
||
const cancelRef = useRef<HTMLButtonElement>(); | ||
function closeDialog() { | ||
appState.accountMenu.setOtherSessionsLogout(false); | ||
} | ||
|
||
return ( | ||
<AlertDialog onDismiss={closeDialog} leastDestructiveRef={cancelRef}> | ||
<div className="sk-modal-content"> | ||
<div className="sn-component"> | ||
<div className="sk-panel"> | ||
<div className="sk-panel-content"> | ||
<div className="sk-panel-section"> | ||
<AlertDialogLabel className="sk-h3 sk-panel-section-title capitalize"> | ||
End all other sessions? | ||
</AlertDialogLabel> | ||
<AlertDialogDescription className="sk-panel-row"> | ||
<p className="color-foreground"> | ||
This action will sign out all other devices signed into your account, | ||
and remove your data from those devices when they next regain connection | ||
to the internet. You may sign back in on those devices at any time. | ||
</p> | ||
</AlertDialogDescription> | ||
<div className="flex my-1 mt-4"> | ||
<button | ||
className="sn-button small neutral" | ||
ref={cancelRef} | ||
onClick={closeDialog} | ||
> | ||
Cancel | ||
</button> | ||
<button | ||
className="sn-button small danger ml-2" | ||
onClick={() => { | ||
application.revokeAllOtherSessions(); | ||
closeDialog(); | ||
application.alertService.alert( | ||
"You have successfully revoked your sessions from other devices.", | ||
undefined, | ||
"Finish" | ||
); | ||
}} | ||
> | ||
End Sessions | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</AlertDialog> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/assets/javascripts/preferences/components/PreferencesGroup.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { FunctionComponent } from 'preact'; | ||
import { HorizontalSeparator } from '@/components/shared/HorizontalSeparator'; | ||
|
||
const HorizontalLine: FunctionComponent<{ index: number; length: number }> = ({ | ||
index, | ||
length, | ||
}) => (index < length - 1 ? <HorizontalSeparator classes="my-4" /> : null); | ||
|
||
export const PreferencesGroup: FunctionComponent = ({ children }) => ( | ||
<div className="bg-default border-1 border-solid rounded border-gray-300 px-6 py-6 flex flex-col"> | ||
{Array.isArray(children) | ||
? children | ||
.filter( | ||
(child) => child != undefined && child !== '' && child !== false | ||
) | ||
.map((child, i, arr) => ( | ||
<> | ||
{child} | ||
<HorizontalLine index={i} length={arr.length} /> | ||
</> | ||
)) | ||
: children} | ||
</div> | ||
); |
41 changes: 8 additions & 33 deletions
41
app/assets/javascripts/preferences/components/PreferencesPane.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/assets/javascripts/preferences/components/PreferencesSegment.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { FunctionComponent } from 'preact'; | ||
|
||
export const PreferencesSegment: FunctionComponent = ({ children }) => ( | ||
<div className="flex flex-col">{children}</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './Content'; | ||
export * from './MenuItem'; | ||
export * from './PreferencesPane'; | ||
export * from './PreferencesGroup'; | ||
export * from './PreferencesSegment'; |
33 changes: 22 additions & 11 deletions
33
app/assets/javascripts/preferences/panes/AccountPreferences.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import { Sync, SubscriptionWrapper, Credentials } from '@/preferences/panes/account'; | ||
import { | ||
Sync, | ||
SubscriptionWrapper, | ||
Credentials, | ||
LogOutWrapper, | ||
} from '@/preferences/panes/account'; | ||
import { PreferencesPane } from '@/preferences/components'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { WebApplication } from '@/ui_models/application'; | ||
import { AppState } from '@/ui_models/app_state'; | ||
|
||
type Props = { | ||
application: WebApplication; | ||
} | ||
export const AccountPreferences = observer(({application}: Props) => { | ||
return ( | ||
<PreferencesPane> | ||
<Credentials application={application} /> | ||
<Sync application={application} /> | ||
<SubscriptionWrapper application={application} /> | ||
</PreferencesPane> | ||
); | ||
}); | ||
appState: AppState; | ||
}; | ||
|
||
export const AccountPreferences = observer( | ||
({ application, appState }: Props) => { | ||
return ( | ||
<PreferencesPane> | ||
<Credentials application={application} /> | ||
<Sync application={application} /> | ||
<SubscriptionWrapper application={application} /> | ||
<LogOutWrapper application={application} appState={appState} /> | ||
</PreferencesPane> | ||
); | ||
} | ||
); |
Oops, something went wrong.