Skip to content

Commit

Permalink
fix(web, mirinae): apply sign-in loader for external auth cases & dif…
Browse files Browse the repository at this point in the history
…ferentiate style type of spinner for each button style type (#1593)

* fix: apply sign-in loader for external auth cases

Signed-off-by: Wanjin Noh <[email protected]>

* fix(button): differentiate style type of spinner for each button style type

Signed-off-by: Wanjin Noh <[email protected]>

---------

Signed-off-by: Wanjin Noh <[email protected]>
  • Loading branch information
WANZARGEN authored Aug 16, 2023
1 parent 82e309a commit 160e36d
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 22 deletions.
1 change: 1 addition & 0 deletions apps/web/src/services/auth/authenticator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ abstract class Authenticator {
try {
if (SpaceRouter.router) {
await store.dispatch('user/signOut');
await store.dispatch('display/hideSignInErrorMessage');
LocalStorageAccessor.removeItem('hideNotificationEmailModal');
await store.dispatch('error/resetErrorState');
await store.dispatch('domain/resetBillingEnabled');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class GoogleAuth extends Authenticator {

static async onSuccess(accessToken) {
try {
store.dispatch('user/startSignIn');
GoogleAuth.accessToken = accessToken;
const credentials = {
access_token: accessToken,
Expand All @@ -46,6 +47,8 @@ class GoogleAuth extends Authenticator {
await GoogleAuth.signOut();
await store.dispatch('display/showSignInErrorMessage');
throw new Error(e);
} finally {
store.dispatch('user/finishSignIn');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AUTH_ROUTE } from '@/services/auth/route-config';
class KbAuth extends Authenticator {
static async signIn(onSignInCallback, query) {
try {
store.dispatch('user/startSignIn');
const clientIP = await SpaceConnector.client.identity.user.getIp();
const credentials = {
secureToken: query.secureToken,
Expand All @@ -25,6 +26,8 @@ class KbAuth extends Authenticator {
if (onSignInCallback) onSignInCallback();
} catch (e) {
await KbAuth.onSignInFail();
} finally {
store.dispatch('user/finishSignIn');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ class KeycloakAuth extends Authenticator {
}

private static async keycloakSignIn(auth) {
if (!auth) {
await KeycloakAuth.onSignInFail();
return;
}
if (KeycloakAuth.keycloak.token && KeycloakAuth.keycloak.idToken) {
// eslint-disable-next-line camelcase
await super.signIn(
{ access_token: KeycloakAuth.keycloak.token },
);
try {
store.dispatch('user/startSignIn');
if (!auth) {
await KeycloakAuth.onSignInFail();
return;
}
if (KeycloakAuth.keycloak.token && KeycloakAuth.keycloak.idToken) {
// eslint-disable-next-line camelcase
await super.signIn(
{ access_token: KeycloakAuth.keycloak.token },
);
}
} catch (e) {
store.dispatch('user/finishSignIn');
throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { store } from '@/store';

import { Authenticator } from '@/services/auth/authenticator';

class SpaceAuth extends Authenticator {
// eslint-disable-next-line class-methods-use-this
static async signIn(userId, credentials, userType?): Promise<void> {
await super.signIn(userId, credentials, userType);
try {
store.dispatch('user/startSignIn');
await super.signIn(userId, credentials, userType);
} finally {
store.dispatch('user/finishSignIn');
}
}

// eslint-disable-next-line class-methods-use-this
Expand Down
6 changes: 1 addition & 5 deletions apps/web/src/services/auth/sign-in/local/template/ID_PW.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default defineComponent({
const state = reactive({
userId: '' as string | undefined,
password: '',
loading: false,
loading: computed(() => store.state.user.isSignInLoading),
});
const validationState = reactive({
Expand Down Expand Up @@ -131,11 +131,9 @@ export default defineComponent({
};
const signIn = async () => {
state.loading = true;
checkUserId();
await checkPassword();
if (!validationState.isIdValid || !validationState.isPasswordValid) {
state.loading = false;
return;
}
const credentials = {
Expand All @@ -153,8 +151,6 @@ export default defineComponent({
ErrorHandler.handleError(e);
state.password = '';
await store.dispatch('display/showSignInErrorMessage');
} finally {
state.loading = false;
}
};
Expand Down
8 changes: 8 additions & 0 deletions apps/web/src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,11 @@ export const getUser = async ({ commit, state }, userId): Promise<void> => {
commit('setUser', userInfo);
}
};

export const startSignIn = ({ commit }) => {
commit('setIsSignInLoading', true);
};

export const finishSignIn = ({ commit }) => {
commit('setIsSignInLoading', false);
};
1 change: 1 addition & 0 deletions apps/web/src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const state: UserState = {
roles: storedUserState.roles,
requiredActions: storedUserState.requiredActions,
emailVerified: storedUserState.emailVerified,
isSignInLoading: false,
};

export default {
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Mutation } from 'vuex';

import type { UserState, UserRole } from './type';

export const setUser = (state: UserState, userInfo: UserState): void => {
Expand Down Expand Up @@ -27,3 +29,7 @@ export const setTimezone = (state: UserState, timezone: string): void => {
export const setRoles = (state: UserState, roles: Array<UserRole>): void => {
state.roles = roles;
};

export const setIsSignInLoading: Mutation<UserState> = (state, isSignInLoading: boolean): void => {
state.isSignInLoading = isSignInLoading;
};
1 change: 1 addition & 0 deletions apps/web/src/store/modules/user/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface UserState {
roles?: Array<UserRole>;
requiredActions?: string[];
emailVerified?: boolean;
isSignInLoading?: boolean;
}

export interface SignInRequest {
Expand Down
12 changes: 10 additions & 2 deletions packages/mirinae/src/inputs/buttons/button/PButton.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,21 @@ export const Template = (args, {argTypes})=>({
{{
components:{ PButton },
template: `
<div style="display:flex; align-items:center; justify-content:center; margin-top: 50px; background-color: white">
<div style="display:flex; align-items:center; justify-content:center; margin-top: 50px; background-color: white; gap: 1rem;">
<p-button
styleType="primary"
:loading="true"
>
<div class="loading-btn">
Loading
Loading (primary)
</div>
</p-button>
<p-button
styleType="tertiary"
:loading="true"
>
<div class="loading-btn">
Loading (tertiary)
</div>
</p-button>
</div>`,
Expand Down
10 changes: 9 additions & 1 deletion packages/mirinae/src/inputs/buttons/button/PButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
>
<p-spinner v-if="loading"
:size="loadingIconSize"
:style-type="spinnerStyleType"
/>
<p-i v-if="iconLeft"
:name="iconLeft"
Expand All @@ -51,7 +52,8 @@ import {
} from 'vue';
import PSpinner from '@/feedbacks/loading/spinner/PSpinner.vue';
import { SPINNER_SIZE } from '@/feedbacks/loading/spinner/type';
import type { SpinnerStyleType } from '@/feedbacks/loading/spinner/type';
import { SPINNER_SIZE, SPINNER_STYLE_TYPE } from '@/feedbacks/loading/spinner/type';
import PI from '@/foundation/icons/PI.vue';
import type { ButtonProps, ButtonSize } from '@/inputs/buttons/button/type';
import { BUTTON_SIZE, BUTTON_STYLE } from '@/inputs/buttons/button/type';
Expand All @@ -67,6 +69,8 @@ const LOADING_SIZE: Record<ButtonSize, string> = {
md: SPINNER_SIZE.sm,
lg: SPINNER_SIZE.sm,
};
const WHITE_SPINNER_TYPES: string[] = [BUTTON_STYLE.primary, BUTTON_STYLE.substitutive, BUTTON_STYLE.highlight, BUTTON_STYLE.positive, BUTTON_STYLE['negative-primary']];
export default defineComponent<ButtonProps>({
name: 'PButton',
components: {
Expand Down Expand Up @@ -122,6 +126,10 @@ export default defineComponent<ButtonProps>({
component: computed(() => (props.href ? 'a' : 'button')),
iconSize: computed(() => ICON_SIZE[props.size ?? ''] ?? ICON_SIZE.md),
loadingIconSize: computed(() => LOADING_SIZE[props.size ?? ''] ?? LOADING_SIZE.md),
spinnerStyleType: computed<SpinnerStyleType>(() => {
if (WHITE_SPINNER_TYPES.includes(props.styleType)) return SPINNER_STYLE_TYPE.white;
return SPINNER_STYLE_TYPE.gray;
}),
});
/* Event */
Expand Down
6 changes: 2 additions & 4 deletions packages/mirinae/src/styles/colorsets.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
palette,
} from '@/styles/colors.cjs';
import colors from '@/styles/colors.cjs';

const {
blue, coral, gray, green, indigo, peacock, red, violet, yellow,
} = palette;
} = colors.palette;

export const MASSIVE_CHART_COLORS = [
violet[400], violet[600], blue[400], blue[600], coral[400], coral[600],
Expand Down

1 comment on commit 160e36d

@vercel
Copy link

@vercel vercel bot commented on 160e36d Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

console – ./

console-git-master-cloudforet.vercel.app
console-cloudforet.vercel.app

Please sign in to comment.