ui: change project edit
This commit is contained in:
parent
7f28f87f5c
commit
b2068ee9d9
3 changed files with 13 additions and 17 deletions
|
|
@ -38,14 +38,15 @@ const NewSiteForm = ({ location: { pathname }, onClose }: Props) => {
|
|||
|
||||
const onSubmit = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (site?.id && site.exists()) {
|
||||
if (!projectsStore.instance) return;
|
||||
if (projectsStore.instance.id && projectsStore.instance.exists()) {
|
||||
projectsStore
|
||||
.updateProject(site.id, site.toData())
|
||||
.updateProject(projectsStore.instance.id, projectsStore.instance.toData())
|
||||
.then((response: any) => {
|
||||
if (!response || !response.errors || response.errors.size === 0) {
|
||||
onClose(null);
|
||||
if (!pathname.includes('onboarding')) {
|
||||
fetchList();
|
||||
void fetchList();
|
||||
}
|
||||
toast.success('Project updated successfully');
|
||||
} else {
|
||||
|
|
@ -53,7 +54,7 @@ const NewSiteForm = ({ location: { pathname }, onClose }: Props) => {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
saveProject(site!).then((response: any) => {
|
||||
saveProject(projectsStore.instance!).then((response: any) => {
|
||||
if (!response || !response.errors || response.errors.size === 0) {
|
||||
onClose(null);
|
||||
searchStore.clearSearch();
|
||||
|
|
|
|||
|
|
@ -55,13 +55,7 @@ export default class ProjectsStore {
|
|||
|
||||
editInstance = (instance: Partial<Project>) => {
|
||||
if (!this.instance) return;
|
||||
Object.keys(instance).forEach((key) => {
|
||||
if (key in this.instance) {
|
||||
this.instance[key] = instance[key];
|
||||
} else {
|
||||
console.error(`Project: Unknown key ${key}`);
|
||||
}
|
||||
})
|
||||
this.instance = this.instance.edit(instance);
|
||||
}
|
||||
|
||||
fetchGDPR = async (siteId: string) => {
|
||||
|
|
@ -189,7 +183,7 @@ export default class ProjectsStore {
|
|||
} catch (error) {
|
||||
console.error('Failed to update site:', error);
|
||||
} finally {
|
||||
this.setLoading
|
||||
this.setLoading(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { makeAutoObservable } from 'mobx';
|
||||
import { makeAutoObservable, runInAction } from 'mobx';
|
||||
import GDPR from './gdpr';
|
||||
|
||||
export default class Project {
|
||||
|
|
@ -27,7 +27,7 @@ export default class Project {
|
|||
|
||||
exists = () => {
|
||||
return !!this.id;
|
||||
}
|
||||
};
|
||||
|
||||
get validate() {
|
||||
return this.name.length > 0;
|
||||
|
|
@ -40,8 +40,9 @@ export default class Project {
|
|||
} else {
|
||||
console.error(`Project: Unknown key ${key}`);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
toData = () => {
|
||||
return {
|
||||
|
|
@ -60,5 +61,5 @@ export default class Project {
|
|||
sampleRate: this.sampleRate,
|
||||
conditionsCount: this.conditionsCount,
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue