fix(editor): Open Community+ enrollment modal only for the instance owner (#11292)

This commit is contained in:
Csaba Tuncsik
2024-10-21 10:02:18 +02:00
committed by GitHub
parent cd15e959c7
commit 76724c3be6
9 changed files with 48 additions and 17 deletions

View File

@@ -93,6 +93,7 @@ import { useExternalHooks } from '@/composables/useExternalHooks';
import { useI18n } from '@/composables/useI18n';
import { useRoute, useRouter } from 'vue-router';
import { useUIStore } from '@/stores/ui.store';
import { getResourcePermissions } from '@/permissions';
const SURVEY_VERSION = 'v4';
@@ -110,7 +111,9 @@ const uiStore = useUIStore();
const formValues = ref<Record<string, string>>({});
const isSaving = ref(false);
const userPermissions = computed(() =>
getResourcePermissions(usersStore.currentUser?.globalScopes),
);
const survey = computed<IFormInputs>(() => [
{
name: COMPANY_TYPE_KEY,
@@ -548,23 +551,30 @@ const onSave = () => {
formBus.emit('submit');
};
const closeCallback = () => {
const isPartOfOnboardingExperiment =
posthogStore.getVariant(MORE_ONBOARDING_OPTIONS_EXPERIMENT.name) ===
MORE_ONBOARDING_OPTIONS_EXPERIMENT.control;
// In case the redirect to homepage for new users didn't happen
// we try again after closing the modal
if (route.name !== VIEWS.HOMEPAGE && !isPartOfOnboardingExperiment) {
void router.replace({ name: VIEWS.HOMEPAGE });
}
};
const closeDialog = () => {
modalBus.emit('close');
uiStore.openModalWithData({
name: COMMUNITY_PLUS_ENROLLMENT_MODAL,
data: {
closeCallback: () => {
const isPartOfOnboardingExperiment =
posthogStore.getVariant(MORE_ONBOARDING_OPTIONS_EXPERIMENT.name) ===
MORE_ONBOARDING_OPTIONS_EXPERIMENT.control;
// In case the redirect to homepage for new users didn't happen
// we try again after closing the modal
if (route.name !== VIEWS.HOMEPAGE && !isPartOfOnboardingExperiment) {
void router.replace({ name: VIEWS.HOMEPAGE });
}
if (userPermissions.value.community.register) {
uiStore.openModalWithData({
name: COMMUNITY_PLUS_ENROLLMENT_MODAL,
data: {
closeCallback,
},
},
});
});
} else {
closeCallback();
}
};
const onSubmit = async (values: IPersonalizationLatestVersion) => {