From 3a9c7c146ef3b5ab9650fbb83e1a338eec73ee3a Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sun, 13 Dec 2020 20:44:04 +0200 Subject: Update question types and interface to match changes in backend --- src/api/question.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/api') diff --git a/src/api/question.ts b/src/api/question.ts index e051459..bdd6b99 100644 --- a/src/api/question.ts +++ b/src/api/question.ts @@ -1,11 +1,17 @@ export enum QuestionType { - Text, - Checkbox, - Radio, - Code + TextArea = "textarea", + Checkbox = "checkbox", + Radio = "radio", + Code = "code", + Select = "select", + ShortText = "short_text", + Range = "range", + Section = "section" } export interface Question { + id: string, name: string, - type: QuestionType + type: QuestionType, + data: { [key: string]: any } } -- cgit v1.2.3 From 296ee9774e53d990f73bf7f56edc5ec351f0609f Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Sun, 13 Dec 2020 20:44:28 +0200 Subject: Update form interface and add features --- src/api/forms.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/api') diff --git a/src/api/forms.ts b/src/api/forms.ts index a4a4981..c20a587 100644 --- a/src/api/forms.ts +++ b/src/api/forms.ts @@ -1,17 +1,22 @@ import { Question, QuestionType } from "./question" -export interface AllFormsForm { - title: string, - id: string, - description: string, - open: boolean +export enum FormFeatures { + Discoverable = "DISCOVERABLE", + RequiresLogin = "REQUIRES_LOGIN", + Open = "OPEN", + CollectEmail = "COLLECT_EMAIL", + DisableAntispam = "DISABLE_ANTISPAM" } -export interface Form extends AllFormsForm { - questions: Array +export interface Form { + id: string, + features: Array, + questions: Array, + name: string, + description: string } -export function getForms(): AllFormsForm[] { +export function getForms(): Form[] { return [ { title: "Ban Appeals", @@ -36,14 +41,16 @@ export function getForms(): AllFormsForm[] { export function getForm(id: string): Promise
{ const data: Form = { - title: "Ban Appeals", + name: "Ban Appeals", id: "ban-appeals", description: "Appealing bans from the Discord server", - open: true, + features: [FormFeatures.Discoverable, FormFeatures.Open], questions: [ { + id: "how-spanish-are-you", name: "How Spanish are you?", - type: QuestionType.Text + type: QuestionType.ShortText, + data: {} } ] } -- cgit v1.2.3 From 1ee5c3b2e5c9339492bd3aa7ef5d0769d554f48c Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Mon, 14 Dec 2020 10:49:39 +0200 Subject: Create Axios client for backend --- src/api/client.ts | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/api/client.ts (limited to 'src/api') diff --git a/src/api/client.ts b/src/api/client.ts new file mode 100644 index 0000000..6d1491a --- /dev/null +++ b/src/api/client.ts @@ -0,0 +1,6 @@ +import axios from "axios"; + + +export default axios.create({ + baseURL: process.env.BACKEND_URL || "https://forms-api.pythondiscord.com/" +}) -- cgit v1.2.3 From 8e2b2764b136b9e742f75f7b4a3621cb56238bc6 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Mon, 14 Dec 2020 10:50:43 +0200 Subject: Update getForms function to fetch data from API --- src/api/forms.ts | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'src/api') diff --git a/src/api/forms.ts b/src/api/forms.ts index c20a587..724d6b7 100644 --- a/src/api/forms.ts +++ b/src/api/forms.ts @@ -1,4 +1,5 @@ import { Question, QuestionType } from "./question" +import ApiClient from "./client"; export enum FormFeatures { Discoverable = "DISCOVERABLE", @@ -16,27 +17,9 @@ export interface Form { description: string } -export function getForms(): Form[] { - return [ - { - title: "Ban Appeals", - id: "ban-appeals", - description: "Appealing bans from the Discord server", - open: true - }, - { - title: "Insights 2020", - id: "insights-2020", - description: "Insights about the Python Discord community", - open: false - }, - { - title: "Code Jam 2099 Sign Ups", - id: "code-jam-2099-sign-up", - description: "Signing up for Python Discord's millionth code jam!", - open: false - } - ] +export async function getForms(): Promise { + const resp = await ApiClient.get("forms/discoverable"); + return resp.data; } export function getForm(id: string): Promise { -- cgit v1.2.3 From 41dc7ef649227673fa0015a1acd923d3be33d470 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Mon, 14 Dec 2020 21:17:10 +0200 Subject: Simplify Axios client baseURL definition Co-authored-by: Joe Banks --- src/api/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api') diff --git a/src/api/client.ts b/src/api/client.ts index 6d1491a..32c1993 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -2,5 +2,5 @@ import axios from "axios"; export default axios.create({ - baseURL: process.env.BACKEND_URL || "https://forms-api.pythondiscord.com/" + baseURL: process.env.BACKEND_URL }) -- cgit v1.2.3