Skip to content

Commit

Permalink
fix(subscription): adapt space-creator for free subscription scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Nov 15, 2021
1 parent 7f2e277 commit 8039ac3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@
<script>
import { ref, reactive, watch } from "vue";
import { useOrganizations } from "@/state/organizations.js";
import { useSpaces } from "@/state/spaces.js";
export default {
props: {
type: {
type: String,
default: "pro",
validator: value => ["free", "pro"].includes(value)
},
organizations: {
type: Array,
required: true
Expand All @@ -132,6 +138,7 @@ export default {
emits: ["space-created"],
setup(props, { emit }) {
const { createOrganization } = useOrganizations();
const { createSpace } = useSpaces();
const mode = ref("create");
const step = ref(1);
Expand Down Expand Up @@ -192,7 +199,12 @@ export default {
const submitSpace = async () => {
try {
newSpaceLoading.value = true;
emit("space-created", { ...newSpace });
if (props.type === "free") {
const createdSpace = await createSpace(newSpace);
emit("space-created", createdSpace);
} else {
emit("space-created", { ...newSpace });
}
step.value = 3;
} finally {
newSpaceLoading.value = false;
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"title": "Add DataPack"
},
"SubscriptionFree": {
"title": "Create Free Plan"
"title": "Create Free Plan",
"spaceCreatedNotification": "You have just created the space {spaceName} in the organization {organizationName}"
},
"SubscriptionPro": {
"title": "Upgrade to pro platform",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
},
"SubscriptionFree": {
"title": "Créer un espace gratuit",
"text": "Vous êtes sur le point de créer votre espace gratuit. Votre espace gratuit inclus: {size}, 6 utilisateurs."
"text": "Vous êtes sur le point de créer votre espace gratuit. Votre espace gratuit inclus: {size}, 6 utilisateurs.",
"spaceCreatedNotification": "Vous venez de créer l'espace {spaceName} dans l'organisation {organizationName}"
},
"SubscriptionPro": {
"title": "Passer à la platforme professionnelle",
Expand Down
13 changes: 13 additions & 0 deletions src/views/subscription-free/SubscriptionFree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</p>
<div class="subscription-free__body__content">
<SpaceCreator
type="free"
:organizations="organizations"
:initialOrga="currentOrga"
@space-created="onSpaceCreated"
Expand All @@ -26,7 +27,9 @@
</template>

<script>
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { useNotifications } from "@/composables/notifications.js";
import { FREE_PLAN_STORAGE } from "@/config/subscription.js";
import routeNames from "@/router/route-names.js";
import { useOrganizations } from "@/state/organizations.js";
Expand All @@ -44,13 +47,23 @@ export default {
ViewHeader
},
setup() {
const { t } = useI18n();
const router = useRouter();
const { pushNotification } = useNotifications();
const { userOrganizations } = useOrganizations();
const { currentOrga } = useSubscriptions();
const size = formatBytes(FREE_PLAN_STORAGE);
const onSpaceCreated = space => {
pushNotification({
type: "success",
title: t("Success"),
message: t("SubscriptionFree.spaceCreatedNotification", {
organizationName: space.organization.name,
spaceName: space.name
})
});
router.push({
name: routeNames.spaceBoard,
params: {
Expand Down
6 changes: 3 additions & 3 deletions src/views/subscription-pro/SubscriptionPro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<ProPlanInfo />
</div>
<div class="subscription-pro__content__body__center">
<ProPlanForm :space="space" @space-created="goToSpaceBoard" />
<ProPlanForm :space="space" @space-created="onSpaceCreated" />
</div>
<div class="subscription-pro__content__body__right">
<SpaceSizePreview
Expand Down Expand Up @@ -84,7 +84,7 @@ export default {
const spaceInfo = ref({});
const newSizeAvailable = ref(+PRO_PLAN_STORAGE);
const goToSpaceBoard = space => {
const onSpaceCreated = space => {
pushNotification({
type: "success",
title: t("Success"),
Expand All @@ -108,7 +108,7 @@ export default {
spaceInfo,
// Methods
formatBytes,
goToSpaceBoard
onSpaceCreated
};
}
};
Expand Down

0 comments on commit 8039ac3

Please sign in to comment.