feat(ui): change flag activity method

This commit is contained in:
nick-delirium 2023-06-22 16:13:35 +02:00
parent 037366e9e7
commit 2e363da443
3 changed files with 16 additions and 1 deletions

View file

@ -12,7 +12,7 @@ function FFlagItem({ flag }: { flag: FeatureFlag }) {
const toggleActivity = () => {
const newValue = !flag.isActive
flag.setIsEnabled(newValue);
featureFlagsStore.updateFlag(flag, true).then(() => {
featureFlagsStore.updateFlagStatus(flag.featureFlagId, newValue).then(() => {
toast.success('Feature flag updated.');
})
.catch(() => {

View file

@ -125,6 +125,14 @@ export default class FeatureFlagsStore {
}
};
updateFlagStatus = async (flagId: number, isActive: boolean) => {
try {
await this.client.updateStatus(flagId, isActive);
} catch (e) {
console.error(e);
}
}
updateFlag = async (flag?: FeatureFlag, skipLoader?: boolean) => {
const usedFlag = flag || this.currentFflag;
if (usedFlag) {

View file

@ -68,6 +68,13 @@ export default class FFlagsService extends BaseService {
.then((j) => j.data || {});
}
updateStatus(flagId: number, isActive: boolean): Promise<void> {
return this.client
.post(`/feature-flags/${flagId}/status`, { isActive })
.then((r) => r.json())
.then((j) => j.data || {});
}
deleteFlag(id: number): Promise<void> {
return this.client
.delete(`/feature-flags/${id}`)