first commit
This commit is contained in:
47
frontend/src/stores/settingsStore.js
Normal file
47
frontend/src/stores/settingsStore.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
import apiClient from "../services/apiClient";
|
||||
|
||||
const DEFAULT_FLAGS = {
|
||||
registration_enabled: true,
|
||||
provider_login_enabled: true,
|
||||
public_sharing_enabled: true,
|
||||
};
|
||||
|
||||
export const useSettingsStore = defineStore("settings", () => {
|
||||
const featureFlags = ref({ ...DEFAULT_FLAGS });
|
||||
const flagsLoaded = ref(false);
|
||||
|
||||
const registrationEnabled = computed(() => !!featureFlags.value.registration_enabled);
|
||||
const providerLoginEnabled = computed(() => !!featureFlags.value.provider_login_enabled);
|
||||
const publicSharingEnabled = computed(() => !!featureFlags.value.public_sharing_enabled);
|
||||
|
||||
const loadFeatureFlags = async (force = false) => {
|
||||
if (flagsLoaded.value && !force) {
|
||||
return featureFlags.value;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await apiClient.get("/api/v1/settings/feature-flags");
|
||||
featureFlags.value = {
|
||||
...DEFAULT_FLAGS,
|
||||
...response.data,
|
||||
};
|
||||
flagsLoaded.value = true;
|
||||
} catch {
|
||||
featureFlags.value = { ...DEFAULT_FLAGS };
|
||||
flagsLoaded.value = true;
|
||||
}
|
||||
|
||||
return featureFlags.value;
|
||||
};
|
||||
|
||||
return {
|
||||
featureFlags,
|
||||
flagsLoaded,
|
||||
registrationEnabled,
|
||||
providerLoginEnabled,
|
||||
publicSharingEnabled,
|
||||
loadFeatureFlags,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user