Use improved backend fields
This commit is contained in:
@@ -17,9 +17,7 @@ export interface Event {
|
||||
end_time: string;
|
||||
image: string;
|
||||
tags: Tag[];
|
||||
tag_id?: number[];
|
||||
visible: boolean;
|
||||
signup_id: number[];
|
||||
signupForm: SignupForm[];
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ export interface Post {
|
||||
content_en: string;
|
||||
publish_time: string;
|
||||
autohide: string;
|
||||
tag_id: number[];
|
||||
tags: number[];
|
||||
visible: boolean;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ class EventCreatePage extends React.Component<EventCreatePageProps, EventCreateP
|
||||
fetchInitialFormData = async (id) => {
|
||||
try {
|
||||
const data = await getEvent(id, true);
|
||||
data.tags = data.tag_id as any;
|
||||
data.signupForm = data.signup_id as any;
|
||||
data.tags = (data.tags as any).map(inst => inst.id);
|
||||
data.signupForm = (data.signupForm as any).map(inst => inst.id);
|
||||
this.setState({
|
||||
formData: data,
|
||||
});
|
||||
@@ -98,24 +98,33 @@ class EventCreatePage extends React.Component<EventCreatePageProps, EventCreateP
|
||||
const { history } = this.props;
|
||||
try {
|
||||
const payload = data.formData;
|
||||
if (typeof payload.image === "string" && payload.image.startsWith("http")) payload.image = undefined;
|
||||
payload.signup_id = payload.signupForm;
|
||||
payload.tag_id = payload.tags;
|
||||
if (typeof payload.image === "string" && payload.image.startsWith("http")) payload.image = undefined;
|
||||
|
||||
if (payload.id === undefined) {
|
||||
const resp = await createEvent(payload);
|
||||
resp.tags = resp.tag_id as any;
|
||||
resp.signupForm = resp.signup_id as any;
|
||||
// TODO: Backend return old data because of Prefetch (used for filtering invisble signupForms from GET)
|
||||
// Copy from old state instead...
|
||||
// resp.tags = (resp.tags as any).map(inst => inst.id);
|
||||
// resp.signupForm = (resp.signupForm as any).map(inst => inst.id);
|
||||
resp.tags = data.formData.tags;
|
||||
resp.signupForm = data.formData.signupForm;
|
||||
this.setState({
|
||||
formData: resp,
|
||||
statusMessage: "Event created successfully",
|
||||
});
|
||||
} else {
|
||||
const resp = await updateEvent(payload);
|
||||
resp.tags = resp.tag_id as any;
|
||||
resp.signupForm = resp.signup_id as any;
|
||||
// TODO: Backend return old data because of Prefetch (used for filtering invisble signupForms from GET)
|
||||
// Copy from old state instead...
|
||||
// resp.tags = (resp.tags as any).map(inst => inst.id);
|
||||
// resp.signupForm = (resp.signupForm as any).map(inst => inst.id);
|
||||
resp.tags = data.formData.tags;
|
||||
resp.signupForm = data.formData.signupForm;
|
||||
this.setState({
|
||||
formData: resp,
|
||||
statusMessage: "Event updated successfully.",
|
||||
statusMessage: "Event updated successfully",
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -47,7 +47,7 @@ class FeedCreatePage extends React.Component<FeedCreatePageProps, FeedCreatePage
|
||||
fetchInitialFormData = async (id) => {
|
||||
try {
|
||||
const data = await getPost(id);
|
||||
data.tags = data.tag_id;
|
||||
// data.tags = data.tag_id;
|
||||
this.setState({
|
||||
formData: data,
|
||||
});
|
||||
@@ -84,14 +84,14 @@ class FeedCreatePage extends React.Component<FeedCreatePageProps, FeedCreatePage
|
||||
|
||||
if (payload.id === undefined) {
|
||||
const resp = await createPost(payload);
|
||||
resp.tags = resp.tag_id;
|
||||
// resp.tags = resp.tags;
|
||||
this.setState({
|
||||
formData: resp,
|
||||
statusMessage: "Post created successfully",
|
||||
});
|
||||
} else {
|
||||
const resp = await updatePost(payload);
|
||||
resp.tags = resp.tag_id;
|
||||
// resp.tags = resp.tag_id;
|
||||
this.setState({
|
||||
formData: resp,
|
||||
statusMessage: "Post updated successfully.",
|
||||
|
||||
Reference in New Issue
Block a user