Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement spinner for 2fa loading #640

Merged
merged 2 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const is2FAEnabled = (
): status is 'two-factor-enabled' => status === 'two-factor-enabled';

export class TwoFactorAuth {
private _status: TwoFactorStatus = 'two-factor-disabled';
private _status: TwoFactorStatus | 'fetching' = 'fetching';
private _errorMessage: string | null;

constructor(
Expand All @@ -47,7 +47,10 @@ export class TwoFactorAuth {

private startActivation(): void {
const setDisabled = action(() => (this._status = 'two-factor-disabled'));
const setEnabled = action(() => this.fetchStatus());
const setEnabled = action(() => {
this._status = 'two-factor-enabled';
this.fetchStatus();
});
this.mfaProvider
.generateMfaSecret()
.then(
Expand Down Expand Up @@ -138,7 +141,7 @@ export class TwoFactorAuth {
return this._errorMessage;
}

get status(): TwoFactorStatus {
get status(): TwoFactorStatus | 'fetching' {
return this._status;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Text,
PreferencesGroup,
PreferencesSegment,
LinkButton,
} from '../../components';
import { Switch } from '../../../components/Switch';
import { observer } from 'mobx-react-lite';
Expand Down Expand Up @@ -46,15 +45,21 @@ const TwoFactorDescription: FunctionComponent<{ auth: TwoFactorAuth }> =

const TwoFactorSwitch: FunctionComponent<{ auth: TwoFactorAuth }> = observer(
({ auth }) => {
if (auth.isLoggedIn() && auth.isMfaFeatureAvailable()) {
return (
<Switch
checked={!is2FADisabled(auth.status)}
onChange={auth.toggle2FA}
/>
);
if (!(auth.isLoggedIn() && auth.isMfaFeatureAvailable())) {
return null;
}
return null;

if (auth.status === 'fetching') {
return <div class="sk-spinner normal info" />;
}

return (
<Switch
checked={!is2FADisabled(auth.status)}
onChange={auth.toggle2FA}
/>
);

}
);

Expand All @@ -70,7 +75,9 @@ export const TwoFactorAuthView: FunctionComponent<{
<TwoFactorTitle auth={auth} />
<TwoFactorDescription auth={auth} />
</div>
<TwoFactorSwitch auth={auth} />
<div className="flex flex-col justify-center items-center min-w-15">
<TwoFactorSwitch auth={auth} />
</div>
</div>
</PreferencesSegment>

Expand All @@ -80,7 +87,7 @@ export const TwoFactorAuthView: FunctionComponent<{
</PreferencesSegment>
)}
</PreferencesGroup>
{is2FAActivation(auth.status) && (
{auth.status !== 'fetching' && is2FAActivation(auth.status) && (
<TwoFactorActivationView activation={auth.status} />
)}
</>
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/_sn.scss
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
min-width: 1.75rem;
}

.min-w-15 {
min-width: 3.75rem;
}

.min-h-1 {
min-height: 0.25rem;
}
Expand All @@ -213,3 +217,4 @@
.pt-2 {
padding-top: 0.5rem;
}

8 changes: 8 additions & 0 deletions app/assets/stylesheets/_stylekit-sub.scss
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ input:focus {
.sk-button:focus-visible, button:focus-visible {
outline: none;
}

.sk-spinner {
&.normal {
width: 1.5rem;
height: 1.5rem;
border-width: 2px;
}
}