Fix admin settings edition

Closes #893

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-09-29 19:06:57 +02:00
parent c924975d40
commit 9d910db040
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -14,10 +14,10 @@
</li> </li>
</ul> </ul>
</nav> </nav>
<section v-if="adminSettings"> <section v-if="settingsToWrite">
<form @submit.prevent="updateSettings"> <form @submit.prevent="updateSettings">
<b-field :label="$t('Instance Name')" label-for="instance-name"> <b-field :label="$t('Instance Name')" label-for="instance-name">
<b-input v-model="adminSettings.instanceName" id="instance-name" /> <b-input v-model="settingsToWrite.instanceName" id="instance-name" />
</b-field> </b-field>
<div class="field"> <div class="field">
<label class="label has-help" for="instance-description">{{ <label class="label has-help" for="instance-description">{{
@ -32,9 +32,9 @@
</small> </small>
<b-input <b-input
type="textarea" type="textarea"
v-model="adminSettings.instanceDescription" v-model="settingsToWrite.instanceDescription"
rows="2" rows="2"
id="instance-name" id="instance-description"
/> />
</div> </div>
<div class="field"> <div class="field">
@ -49,7 +49,7 @@
}} }}
</small> </small>
<b-input <b-input
v-model="adminSettings.instanceSlogan" v-model="settingsToWrite.instanceSlogan"
:placeholder="$t('Gather ⋅ Organize ⋅ Mobilize')" :placeholder="$t('Gather ⋅ Organize ⋅ Mobilize')"
id="instance-slogan" id="instance-slogan"
/> />
@ -61,11 +61,11 @@
<small> <small>
{{ $t("Can be an email or a link, or just plain text.") }} {{ $t("Can be an email or a link, or just plain text.") }}
</small> </small>
<b-input v-model="adminSettings.contact" id="instance-contact" /> <b-input v-model="settingsToWrite.contact" id="instance-contact" />
</div> </div>
<b-field :label="$t('Allow registrations')"> <b-field :label="$t('Allow registrations')">
<b-switch v-model="adminSettings.registrationsOpen"> <b-switch v-model="settingsToWrite.registrationsOpen">
<p class="content" v-if="adminSettings.registrationsOpen"> <p class="content" v-if="settingsToWrite.registrationsOpen">
{{ $t("Registration is allowed, anyone can register.") }} {{ $t("Registration is allowed, anyone can register.") }}
</p> </p>
<p class="content" v-else>{{ $t("Registration is closed.") }}</p> <p class="content" v-else>{{ $t("Registration is closed.") }}</p>
@ -105,7 +105,7 @@
</small> </small>
<b-input <b-input
type="textarea" type="textarea"
v-model="adminSettings.instanceLongDescription" v-model="settingsToWrite.instanceLongDescription"
rows="4" rows="4"
id="instance-long-description" id="instance-long-description"
/> />
@ -123,7 +123,7 @@
</small> </small>
<b-input <b-input
type="textarea" type="textarea"
v-model="adminSettings.instanceRules" v-model="settingsToWrite.instanceRules"
id="instance-rules" id="instance-rules"
/> />
</div> </div>
@ -136,7 +136,7 @@
</legend> </legend>
<b-field> <b-field>
<b-radio <b-radio
v-model="adminSettings.instanceTermsType" v-model="settingsToWrite.instanceTermsType"
name="instanceTermsType" name="instanceTermsType"
:native-value="InstanceTermsType.DEFAULT" :native-value="InstanceTermsType.DEFAULT"
>{{ $t("Default Mobilizon terms") }}</b-radio >{{ $t("Default Mobilizon terms") }}</b-radio
@ -144,7 +144,7 @@
</b-field> </b-field>
<b-field> <b-field>
<b-radio <b-radio
v-model="adminSettings.instanceTermsType" v-model="settingsToWrite.instanceTermsType"
name="instanceTermsType" name="instanceTermsType"
:native-value="InstanceTermsType.URL" :native-value="InstanceTermsType.URL"
>{{ $t("Custom URL") }}</b-radio >{{ $t("Custom URL") }}</b-radio
@ -152,7 +152,7 @@
</b-field> </b-field>
<b-field> <b-field>
<b-radio <b-radio
v-model="adminSettings.instanceTermsType" v-model="settingsToWrite.instanceTermsType"
name="instanceTermsType" name="instanceTermsType"
:native-value="InstanceTermsType.CUSTOM" :native-value="InstanceTermsType.CUSTOM"
>{{ $t("Custom text") }}</b-radio >{{ $t("Custom text") }}</b-radio
@ -164,7 +164,8 @@
<div <div
class="notification" class="notification"
v-if=" v-if="
adminSettings.instanceTermsType === InstanceTermsType.DEFAULT settingsToWrite.instanceTermsType ===
InstanceTermsType.DEFAULT
" "
> >
<b>{{ $t("Default") }}</b> <b>{{ $t("Default") }}</b>
@ -189,7 +190,9 @@
</div> </div>
<div <div
class="notification" class="notification"
v-if="adminSettings.instanceTermsType === InstanceTermsType.URL" v-if="
settingsToWrite.instanceTermsType === InstanceTermsType.URL
"
> >
<b>{{ $t("URL") }}</b> <b>{{ $t("URL") }}</b>
<p class="content"> <p class="content">
@ -199,7 +202,7 @@
<div <div
class="notification" class="notification"
v-if=" v-if="
adminSettings.instanceTermsType === InstanceTermsType.CUSTOM settingsToWrite.instanceTermsType === InstanceTermsType.CUSTOM
" "
> >
<b>{{ $t("Custom") }}</b> <b>{{ $t("Custom") }}</b>
@ -223,15 +226,25 @@
</b-field> </b-field>
<b-field <b-field
:label="$t('Instance Terms URL')" :label="$t('Instance Terms URL')"
v-if="adminSettings.instanceTermsType === InstanceTermsType.URL" label-for="instanceTermsUrl"
v-if="settingsToWrite.instanceTermsType === InstanceTermsType.URL"
> >
<b-input type="URL" v-model="adminSettings.instanceTermsUrl" /> <b-input
type="URL"
v-model="settingsToWrite.instanceTermsUrl"
id="instanceTermsUrl"
/>
</b-field> </b-field>
<b-field <b-field
:label="$t('Instance Terms')" :label="$t('Instance Terms')"
v-if="adminSettings.instanceTermsType === InstanceTermsType.CUSTOM" label-for="instanceTerms"
v-if="settingsToWrite.instanceTermsType === InstanceTermsType.CUSTOM"
> >
<b-input type="textarea" v-model="adminSettings.instanceTerms" /> <b-input
type="textarea"
v-model="settingsToWrite.instanceTerms"
id="instanceTerms"
/>
</b-field> </b-field>
<b-field :label="$t('Instance Privacy Policy Source')"> <b-field :label="$t('Instance Privacy Policy Source')">
<div class="columns"> <div class="columns">
@ -242,7 +255,7 @@
</legend> </legend>
<b-field> <b-field>
<b-radio <b-radio
v-model="adminSettings.instancePrivacyPolicyType" v-model="settingsToWrite.instancePrivacyPolicyType"
name="instancePrivacyType" name="instancePrivacyType"
:native-value="InstancePrivacyType.DEFAULT" :native-value="InstancePrivacyType.DEFAULT"
>{{ $t("Default Mobilizon privacy policy") }}</b-radio >{{ $t("Default Mobilizon privacy policy") }}</b-radio
@ -250,7 +263,7 @@
</b-field> </b-field>
<b-field> <b-field>
<b-radio <b-radio
v-model="adminSettings.instancePrivacyPolicyType" v-model="settingsToWrite.instancePrivacyPolicyType"
name="instancePrivacyType" name="instancePrivacyType"
:native-value="InstancePrivacyType.URL" :native-value="InstancePrivacyType.URL"
>{{ $t("Custom URL") }}</b-radio >{{ $t("Custom URL") }}</b-radio
@ -258,7 +271,7 @@
</b-field> </b-field>
<b-field> <b-field>
<b-radio <b-radio
v-model="adminSettings.instancePrivacyPolicyType" v-model="settingsToWrite.instancePrivacyPolicyType"
name="instancePrivacyType" name="instancePrivacyType"
:native-value="InstancePrivacyType.CUSTOM" :native-value="InstancePrivacyType.CUSTOM"
>{{ $t("Custom text") }}</b-radio >{{ $t("Custom text") }}</b-radio
@ -270,7 +283,7 @@
<div <div
class="notification" class="notification"
v-if=" v-if="
adminSettings.instancePrivacyPolicyType === settingsToWrite.instancePrivacyPolicyType ===
InstancePrivacyType.DEFAULT InstancePrivacyType.DEFAULT
" "
> >
@ -292,7 +305,7 @@
<div <div
class="notification" class="notification"
v-if=" v-if="
adminSettings.instancePrivacyPolicyType === settingsToWrite.instancePrivacyPolicyType ===
InstancePrivacyType.URL InstancePrivacyType.URL
" "
> >
@ -304,7 +317,7 @@
<div <div
class="notification" class="notification"
v-if=" v-if="
adminSettings.instancePrivacyPolicyType === settingsToWrite.instancePrivacyPolicyType ===
InstancePrivacyType.CUSTOM InstancePrivacyType.CUSTOM
" "
> >
@ -329,25 +342,30 @@
</b-field> </b-field>
<b-field <b-field
:label="$t('Instance Privacy Policy URL')" :label="$t('Instance Privacy Policy URL')"
label-for="instancePrivacyPolicyUrl"
v-if=" v-if="
adminSettings.instancePrivacyPolicyType === InstancePrivacyType.URL settingsToWrite.instancePrivacyPolicyType ===
InstancePrivacyType.URL
" "
> >
<b-input <b-input
type="URL" type="URL"
v-model="adminSettings.instancePrivacyPolicyUrl" v-model="settingsToWrite.instancePrivacyPolicyUrl"
id="instancePrivacyPolicyUrl"
/> />
</b-field> </b-field>
<b-field <b-field
:label="$t('Instance Privacy Policy')" :label="$t('Instance Privacy Policy')"
label-for="instancePrivacyPolicy"
v-if=" v-if="
adminSettings.instancePrivacyPolicyType === settingsToWrite.instancePrivacyPolicyType ===
InstancePrivacyType.CUSTOM InstancePrivacyType.CUSTOM
" "
> >
<b-input <b-input
type="textarea" type="textarea"
v-model="adminSettings.instancePrivacyPolicy" v-model="settingsToWrite.instancePrivacyPolicy"
id="instancePrivacyPolicy"
/> />
</b-field> </b-field>
<b-button native-type="submit" type="is-primary">{{ <b-button native-type="submit" type="is-primary">{{
@ -358,7 +376,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Vue } from "vue-property-decorator"; import { Component, Vue, Watch } from "vue-property-decorator";
import { import {
ADMIN_SETTINGS, ADMIN_SETTINGS,
SAVE_ADMIN_SETTINGS, SAVE_ADMIN_SETTINGS,
@ -380,7 +398,29 @@ import RouteName from "../../router/name";
}, },
}) })
export default class Settings extends Vue { export default class Settings extends Vue {
adminSettings!: IAdminSettings; adminSettings: IAdminSettings = {
instanceName: "",
instanceDescription: "",
instanceSlogan: "",
instanceLongDescription: "",
contact: "",
instanceTerms: "",
instanceTermsType: InstanceTermsType.DEFAULT,
instanceTermsUrl: null,
instancePrivacyPolicy: "",
instancePrivacyPolicyType: InstanceTermsType.DEFAULT,
instancePrivacyPolicyUrl: null,
instanceRules: "",
registrationsOpen: false,
instanceLanguages: [],
};
settingsToWrite: IAdminSettings = { ...this.adminSettings };
@Watch("adminSettings")
updateSettingsToWrite(): void {
this.settingsToWrite = { ...this.adminSettings };
}
languages!: ILanguage[]; languages!: ILanguage[];
@ -408,7 +448,7 @@ export default class Settings extends Vue {
} }
async updateSettings(): Promise<void> { async updateSettings(): Promise<void> {
const variables = { ...this.adminSettings }; const variables = { ...this.settingsToWrite };
try { try {
await this.$apollo.mutate({ await this.$apollo.mutate({
mutation: SAVE_ADMIN_SETTINGS, mutation: SAVE_ADMIN_SETTINGS,