debian-mirror-gitlab/app/assets/javascripts/jira_connect/subscriptions/components/app.vue

110 lines
2.7 KiB
Vue
Raw Normal View History

2021-01-29 00:20:46 +05:30
<script>
2022-04-04 11:22:00 +05:30
import { GlAlert, GlLink, GlSprintf } from '@gitlab/ui';
2021-12-11 22:18:48 +05:30
import { isEmpty } from 'lodash';
2021-04-17 20:07:23 +05:30
import { mapState, mapMutations } from 'vuex';
2021-12-11 22:18:48 +05:30
import { retrieveAlert } from '~/jira_connect/subscriptions/utils';
2022-05-07 20:08:51 +05:30
import { I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE } from '../constants';
2021-04-17 20:07:23 +05:30
import { SET_ALERT } from '../store/mutation_types';
2022-04-04 11:22:00 +05:30
import SignInPage from '../pages/sign_in.vue';
import SubscriptionsPage from '../pages/subscriptions.vue';
2022-01-26 12:08:38 +05:30
import UserLink from './user_link.vue';
2022-04-04 11:22:00 +05:30
import CompatibilityAlert from './compatibility_alert.vue';
2021-03-08 18:12:59 +05:30
2021-02-22 17:27:13 +05:30
export default {
name: 'JiraConnectApp',
2021-03-08 18:12:59 +05:30
components: {
GlAlert,
2021-04-17 20:07:23 +05:30
GlLink,
GlSprintf,
2022-01-26 12:08:38 +05:30
UserLink,
2022-04-04 11:22:00 +05:30
CompatibilityAlert,
SignInPage,
SubscriptionsPage,
2021-03-08 18:12:59 +05:30
},
2021-03-11 19:13:27 +05:30
inject: {
usersPath: {
default: '',
},
2021-12-11 22:18:48 +05:30
subscriptions: {
default: [],
},
2021-03-11 19:13:27 +05:30
},
2022-05-07 20:08:51 +05:30
data() {
return {
user: null,
};
},
2021-02-22 17:27:13 +05:30
computed: {
2021-04-17 20:07:23 +05:30
...mapState(['alert']),
shouldShowAlert() {
return Boolean(this.alert?.message);
},
2021-12-11 22:18:48 +05:30
hasSubscriptions() {
return !isEmpty(this.subscriptions);
},
userSignedIn() {
2022-05-07 20:08:51 +05:30
return Boolean(!this.usersPath || this.user);
2021-02-22 17:27:13 +05:30
},
},
2021-03-11 19:13:27 +05:30
created() {
2021-04-17 20:07:23 +05:30
this.setInitialAlert();
2021-03-11 19:13:27 +05:30
},
methods: {
2021-04-17 20:07:23 +05:30
...mapMutations({
setAlert: SET_ALERT,
}),
setInitialAlert() {
const { linkUrl, title, message, variant } = retrieveAlert() || {};
this.setAlert({ linkUrl, title, message, variant });
},
2022-05-07 20:08:51 +05:30
onSignInOauth(user) {
this.user = user;
},
onSignInError() {
this.setAlert({
message: I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE,
variant: 'danger',
});
},
2021-03-11 19:13:27 +05:30
},
2021-02-22 17:27:13 +05:30
};
2021-01-29 00:20:46 +05:30
</script>
2021-03-08 18:12:59 +05:30
2021-01-29 00:20:46 +05:30
<template>
2021-03-08 18:12:59 +05:30
<div>
2022-04-04 11:22:00 +05:30
<compatibility-alert />
2021-04-17 20:07:23 +05:30
<gl-alert
v-if="shouldShowAlert"
class="gl-mb-7"
:variant="alert.variant"
:title="alert.title"
2022-04-04 11:22:00 +05:30
data-testid="jira-connect-persisted-alert"
2021-04-17 20:07:23 +05:30
@dismiss="setAlert"
>
<gl-sprintf v-if="alert.linkUrl" :message="alert.message">
<template #link="{ content }">
<gl-link :href="alert.linkUrl" target="_blank">{{ content }}</gl-link>
</template>
</gl-sprintf>
<template v-else>
{{ alert.message }}
</template>
2021-03-08 18:12:59 +05:30
</gl-alert>
2022-05-07 20:08:51 +05:30
<user-link :user-signed-in="userSignedIn" :has-subscriptions="hasSubscriptions" :user="user" />
2022-01-26 12:08:38 +05:30
2021-12-11 22:18:48 +05:30
<h2 class="gl-text-center gl-mb-7">{{ s__('JiraService|GitLab for Jira Configuration') }}</h2>
2022-04-04 11:22:00 +05:30
<div class="gl-layout-w-limited gl-mx-auto gl-px-5 gl-mb-7">
2022-05-07 20:08:51 +05:30
<sign-in-page
v-if="!userSignedIn"
:has-subscriptions="hasSubscriptions"
@sign-in-oauth="onSignInOauth"
@error="onSignInError"
/>
2022-04-04 11:22:00 +05:30
<subscriptions-page v-else :has-subscriptions="hasSubscriptions" />
2021-03-08 18:12:59 +05:30
</div>
</div>
2021-01-29 00:20:46 +05:30
</template>