2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2020-02-18 08:57:00 +01:00
|
|
|
<section class="section container">
|
|
|
|
<h1>{{ $t("Create a new group") }}</h1>
|
2019-09-02 10:50:00 +02:00
|
|
|
|
|
|
|
<div>
|
2019-09-12 11:34:01 +02:00
|
|
|
<b-field :label="$t('Group name')">
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-input aria-required="true" required v-model="group.preferredUsername" />
|
2019-09-02 10:50:00 +02:00
|
|
|
</b-field>
|
|
|
|
|
2019-09-12 11:34:01 +02:00
|
|
|
<b-field :label="$t('Group full name')">
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-input aria-required="true" required v-model="group.name" />
|
2019-09-02 10:50:00 +02:00
|
|
|
</b-field>
|
|
|
|
|
2019-09-12 11:34:01 +02:00
|
|
|
<b-field :label="$t('Description')">
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-input aria-required="true" required v-model="group.summary" type="textarea" />
|
2019-09-02 10:50:00 +02:00
|
|
|
</b-field>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
Avatar
|
2020-02-18 08:57:00 +01:00
|
|
|
<picture-upload v-model="avatarFile" />
|
2019-09-02 10:50:00 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
Banner
|
2020-02-18 08:57:00 +01:00
|
|
|
<picture-upload v-model="avatarFile" />
|
2019-09-02 10:50:00 +02:00
|
|
|
</div>
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
<button class="button is-primary" @click="createGroup()">{{ $t("Create my group") }}</button>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
2020-02-18 08:57:00 +01:00
|
|
|
</section>
|
2019-01-21 15:08:22 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Vue } from "vue-property-decorator";
|
|
|
|
import { Group, IPerson } from "@/types/actor";
|
2020-08-14 11:32:23 +02:00
|
|
|
import { CURRENT_ACTOR_CLIENT } from "@/graphql/actor";
|
|
|
|
import { CREATE_GROUP } from "@/graphql/group";
|
2020-02-18 08:57:00 +01:00
|
|
|
import PictureUpload from "@/components/PictureUpload.vue";
|
|
|
|
import RouteName from "../../router/name";
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-09-02 10:50:00 +02:00
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
PictureUpload,
|
|
|
|
},
|
|
|
|
apollo: {
|
2019-09-11 09:59:01 +02:00
|
|
|
currentActor: {
|
|
|
|
query: CURRENT_ACTOR_CLIENT,
|
2019-09-02 10:50:00 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2019-01-21 15:08:22 +01:00
|
|
|
export default class CreateGroup extends Vue {
|
2019-09-11 09:59:01 +02:00
|
|
|
currentActor!: IPerson;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-09-02 10:50:00 +02:00
|
|
|
group = new Group();
|
|
|
|
|
|
|
|
avatarFile: File | null = null;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-09-02 10:50:00 +02:00
|
|
|
bannerFile: File | null = null;
|
|
|
|
|
|
|
|
async createGroup() {
|
|
|
|
try {
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: CREATE_GROUP,
|
|
|
|
variables: this.buildVariables(),
|
|
|
|
update: (store, { data: { createGroup } }) => {
|
|
|
|
// TODO: update group list cache
|
|
|
|
},
|
|
|
|
});
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
await this.$router.push({
|
|
|
|
name: RouteName.GROUP,
|
|
|
|
params: { identityName: this.group.preferredUsername },
|
|
|
|
});
|
2019-09-02 10:50:00 +02:00
|
|
|
|
|
|
|
this.$notifier.success(
|
2020-02-18 08:57:00 +01:00
|
|
|
this.$t("Group {displayName} created", {
|
|
|
|
displayName: this.group.displayName(),
|
|
|
|
}) as string
|
2019-09-02 10:50:00 +02:00
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
this.handleError(err);
|
|
|
|
}
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 10:50:00 +02:00
|
|
|
private buildVariables() {
|
|
|
|
let avatarObj = {};
|
|
|
|
let bannerObj = {};
|
|
|
|
|
|
|
|
if (this.avatarFile) {
|
|
|
|
avatarObj = {
|
|
|
|
avatar: {
|
|
|
|
picture: {
|
|
|
|
name: this.avatarFile.name,
|
|
|
|
alt: `${this.group.preferredUsername}'s avatar`,
|
|
|
|
file: this.avatarFile,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.bannerFile) {
|
|
|
|
bannerObj = {
|
|
|
|
picture: {
|
|
|
|
name: this.bannerFile.name,
|
|
|
|
alt: `${this.group.preferredUsername}'s banner`,
|
|
|
|
file: this.bannerFile,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const currentActor = {
|
2019-09-11 09:59:01 +02:00
|
|
|
creatorActorId: this.currentActor.id,
|
2019-01-21 15:08:22 +01:00
|
|
|
};
|
2019-09-02 10:50:00 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
return {
|
|
|
|
...this.group,
|
|
|
|
...avatarObj,
|
|
|
|
...bannerObj,
|
|
|
|
...currentActor,
|
|
|
|
};
|
2019-09-02 10:50:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private handleError(err: any) {
|
|
|
|
console.error(err);
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.markdown-render h1 {
|
|
|
|
font-size: 2em;
|
|
|
|
}
|
|
|
|
</style>
|