aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/forms.ts
blob: 0721dcf7cf1994e62db4308f309dd4d563ed151b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Question } from "./question";
import ApiClient from "./client";

export enum FormFeatures {
    Discoverable = "DISCOVERABLE",
    RequiresLogin = "REQUIRES_LOGIN",
    Open = "OPEN",
    CollectEmail = "COLLECT_EMAIL",
    DisableAntispam = "DISABLE_ANTISPAM",
    WebhookEnabled = "WEBHOOK_ENABLED"
}

export interface Form {
    id: string,
    features: Array<FormFeatures>,
    webhook: WebHook | null,
    questions: Array<Question>,
    name: string,
    description: string,
    submitted_text: string | null
}

export interface Precheck {
    severity: "warning" | "danger" | "secondary",
    message: string
}

export interface SubmissionPrecheck {
    can_submit: boolean,
    problems: Array<Precheck>
}

export interface FormWithAncillaryData extends Form {
    submission_precheck: SubmissionPrecheck
}

export interface WebHook {
    url: string,
    message: string | null
}

export async function getForms(): Promise<Form[]> {
    const fetch_response = await ApiClient.get("forms/discoverable");
    return fetch_response.data;
}

export async function getForm(id: string): Promise<FormWithAncillaryData> {
    const fetch_response = await ApiClient.get(`forms/${id}`);
    return fetch_response.data;
}