Merge branch 'master' into 'production'
Few form fixes See merge request sahkoinsinoorikilta/vtmk/web2.0-frontend!10
This commit is contained in:
@@ -6,6 +6,7 @@ import { Question } from "@components/SignupQuestionsWidget";
|
||||
export interface SignupForm {
|
||||
id?: number;
|
||||
title: string;
|
||||
visible: boolean;
|
||||
start_time: string;
|
||||
end_time: string;
|
||||
questions: Question[];
|
||||
@@ -20,9 +21,12 @@ export interface SignupForm {
|
||||
};
|
||||
}
|
||||
|
||||
export async function getForms(): Promise<SignupForm[]> {
|
||||
export async function getForms(auth = false): Promise<SignupForm[]> {
|
||||
try {
|
||||
const resp = await axios.get(url);
|
||||
const headers = auth ? { "Authorization": getAuthHeader() } : null;
|
||||
const resp = await axios.get(url, {
|
||||
headers
|
||||
});
|
||||
const { results } = resp.data;
|
||||
return results;
|
||||
} catch (err) {
|
||||
@@ -31,9 +35,12 @@ export async function getForms(): Promise<SignupForm[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getForm(id: number): Promise<SignupForm> {
|
||||
export async function getForm(id: number, auth = false): Promise<SignupForm> {
|
||||
try {
|
||||
const resp = await axios.get(`${url}${id}/`);
|
||||
const headers = auth ? { "Authorization": getAuthHeader() } : null;
|
||||
const resp = await axios.get(`${url}${id}/`, {
|
||||
headers
|
||||
});
|
||||
return resp.data;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
@@ -47,7 +47,7 @@ class AdminSignupPage extends React.Component<AdminSignupPageProps, AdminSignupP
|
||||
}
|
||||
|
||||
fetchSignupForms = async () => {
|
||||
const getSignupFormsPromise = getForms();
|
||||
const getSignupFormsPromise = getForms(true);
|
||||
try {
|
||||
const signupForms = await getSignupFormsPromise;
|
||||
this.setState({
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import React from "react";
|
||||
import { Helmet } from "react-helmet";
|
||||
import "./EventCreatePage.scss";
|
||||
import { isAuthenticated } from "@utils/auth";
|
||||
import Form from "react-jsonschema-form";
|
||||
import { Tag, getTags } from "@models/Tag";
|
||||
import { SignupForm, getForms } from "@models/SignupForm";
|
||||
import { createEvent, getEvent, updateEvent, Event } from "@models/Event";
|
||||
import DatetimeWidget from "@components/DatetimeWidget";
|
||||
import SectionDividerWidget from "@components/SectionDividerWidget";
|
||||
import Icon from "@components/Icon";
|
||||
import { IconType } from "@components/Icon/Icon";
|
||||
|
||||
const widgets = {
|
||||
datetime: DatetimeWidget,
|
||||
@@ -84,7 +81,7 @@ class EventCreatePage extends React.Component<EventCreatePageProps, EventCreateP
|
||||
|
||||
fetchSignupForms = async () => {
|
||||
try {
|
||||
const signupForm = await getForms();
|
||||
const signupForm = await getForms(true);
|
||||
this.setState({
|
||||
signupForm
|
||||
})
|
||||
@@ -98,14 +95,10 @@ class EventCreatePage extends React.Component<EventCreatePageProps, EventCreateP
|
||||
}
|
||||
|
||||
onSubmit = async (data) => {
|
||||
console.log("submitted, data:");
|
||||
console.log(data.formData);
|
||||
|
||||
const { history } = this.props;
|
||||
|
||||
try {
|
||||
const payload = data.formData;
|
||||
if (payload.image.startsWith("http")) payload.image = undefined;
|
||||
if (typeof payload.image === "string" && payload.image.startsWith("http")) payload.image = undefined;
|
||||
payload.signup_id = payload.signupForm;
|
||||
payload.tag_id = payload.tags;
|
||||
if (payload.id === undefined) {
|
||||
@@ -134,6 +127,7 @@ class EventCreatePage extends React.Component<EventCreatePageProps, EventCreateP
|
||||
|
||||
onError = (data) => {
|
||||
console.error("error, data:");
|
||||
console.log(this.state.formData);
|
||||
console.log(data);
|
||||
}
|
||||
|
||||
@@ -197,19 +191,21 @@ class EventCreatePage extends React.Component<EventCreatePageProps, EventCreateP
|
||||
default: tomorrowDatetime,
|
||||
},
|
||||
signupForm: {
|
||||
type: ["array"],
|
||||
type: "array",
|
||||
title: "Signup forms",
|
||||
items: {
|
||||
type: "number",
|
||||
// TODO: A bug here, DB must have at least one SignupForm, otherwise cannot submit
|
||||
enum: [...signupForm.map(form => form.id)],
|
||||
enumNames: [...signupForm.map(form => form.title)],
|
||||
enum: signupForm.map(form => form.id),
|
||||
enumNames: signupForm.map(form => form.title),
|
||||
},
|
||||
uniqueItems: true,
|
||||
},
|
||||
image: {
|
||||
"type": ["string", "null"],
|
||||
"format": formData.image ? "uri-reference" : "data-url",
|
||||
"title": "Override tag icon with image"
|
||||
type: ["string", "null"],
|
||||
format: formData.image ? "uri-reference" : "data-url",
|
||||
title: "Override tag icon with image",
|
||||
default: undefined
|
||||
},
|
||||
finnish_section_divider: {
|
||||
title: "Finnish",
|
||||
|
||||
@@ -44,7 +44,7 @@ class SignupCreatePage extends React.Component<SignupCreatePageProps, SignupCrea
|
||||
|
||||
fetchInitialFormData = async (id: number) => {
|
||||
try {
|
||||
const data = await getForm(id);
|
||||
const data = await getForm(id, true);
|
||||
this.setState({
|
||||
formData: {
|
||||
...data,
|
||||
@@ -133,13 +133,13 @@ class SignupCreatePage extends React.Component<SignupCreatePageProps, SignupCrea
|
||||
visible: {
|
||||
type: "boolean",
|
||||
title: "Visible",
|
||||
default: true,
|
||||
default: false,
|
||||
},
|
||||
quota: {
|
||||
type: "integer",
|
||||
title: "Quota",
|
||||
minimum: 0,
|
||||
default: null,
|
||||
default: 0,
|
||||
},
|
||||
start_time: {
|
||||
type: "string",
|
||||
|
||||
@@ -26,7 +26,7 @@ const renderList = (signUpForm: SignupForm) => {
|
||||
return (
|
||||
<>
|
||||
<h6>
|
||||
Ilmoittautuneet {signUpForm.quota && (`(${signUpForm.signups.length}/${signUpForm.quota})`)}:
|
||||
Ilmoittautuneet{signUpForm.quota > 0 && (` (${signUpForm.signups.length}/${signUpForm.quota})`)}:
|
||||
</h6>
|
||||
<ol>
|
||||
{signUpForm.signups.map((s, idx) => (
|
||||
|
||||
Reference in New Issue
Block a user