aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2020-12-14 19:18:19 +0000
committerGravatar GitHub <[email protected]>2020-12-14 19:18:19 +0000
commita1963eb56f9682a6315a06a075d09314822dbfd9 (patch)
treed0856e1326516447a33951de623770787f6ef996 /src/api
parentMerge pull request #29 from python-discord/dependabot/npm_and_yarn/ini-1.3.8 (diff)
parentSimplify Axios client baseURL definition (diff)
Merge pull request #30 from python-discord/ks123/discovery
Diffstat (limited to 'src/api')
-rw-r--r--src/api/client.ts6
-rw-r--r--src/api/forms.ts52
-rw-r--r--src/api/question.ts16
3 files changed, 38 insertions, 36 deletions
diff --git a/src/api/client.ts b/src/api/client.ts
new file mode 100644
index 0000000..32c1993
--- /dev/null
+++ b/src/api/client.ts
@@ -0,0 +1,6 @@
+import axios from "axios";
+
+
+export default axios.create({
+ baseURL: process.env.BACKEND_URL
+})
diff --git a/src/api/forms.ts b/src/api/forms.ts
index a4a4981..724d6b7 100644
--- a/src/api/forms.ts
+++ b/src/api/forms.ts
@@ -1,49 +1,39 @@
import { Question, QuestionType } from "./question"
+import ApiClient from "./client";
-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<Question>
+export interface Form {
+ id: string,
+ features: Array<FormFeatures>,
+ questions: Array<Question>,
+ name: string,
+ description: string
}
-export function getForms(): AllFormsForm[] {
- 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<Form[]> {
+ const resp = await ApiClient.get("forms/discoverable");
+ return resp.data;
}
export function getForm(id: string): Promise<Form> {
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: {}
}
]
}
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 }
}