-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathserver-side.tsx
134 lines (130 loc) · 3.61 KB
/
server-side.tsx
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import * as React from "react"
import { GetStaticPropsResult } from "next"
import Head from "next/head"
import Link from "next/link"
import withCustomStyles from "../components/withCustomStyles"
import {
resolveWebformContent,
Webform,
components,
WebformProps,
} from "nextjs-drupal-webform"
import { drupal } from "basic-starter/lib/drupal"
import classNames from "classnames"
import WebformButton from "../components/WebformButton"
interface WebformPageProps {
webform: WebformProps
}
export default function WebformPage({ webform }: WebformPageProps) {
const labelProps = {
className: classNames(["block", "text-sm", "font-medium", "text-gray-700"]),
}
const fieldProps = {
className: classNames([
"relative",
"block",
"w-full px-3",
"py-2 mt-1 text-gray-900",
"placeholder-gray-500",
"border border-gray-300",
"rounded-md appearance-none",
"focus:outline-none",
"focus:ring-black",
"focus:border-black",
"focus:z-10",
"sm:text-sm",
]),
}
const wrapperProps = {
className: classNames(["space-y-3"]),
}
const buttonProps = {
className: classNames([
"px-4",
"py-2",
"text-sm font-medium",
"text-white",
"bg-black",
"border border-transparent",
"rounded-md",
"shadow-sm",
"hover:bg-black",
]),
"data-cy": "btn-submit",
}
return (
<>
<Head>
<title>Next.js for Drupal | Webform Example</title>
</Head>
<div className="container max-w-2xl px-6 py-10 mx-auto">
<article className="prose lg:prose-xl">
<h1>Next.js for Drupal</h1>
<h2>Webform Example - Server Side</h2>
<p>
This example uses the{" "}
<a href="https://www.drupal.org/project/next_webform">
Next.js Webform
</a>{" "}
library to render and submit forms built using the Drupal Webform
module.
</p>
<div className="w-full max-w-md p-6 space-y-4 border rounded-md shadow">
<Webform
id="contact"
data={webform}
className="space-y-6"
customComponents={{
textfield: withCustomStyles(
components.textfield,
fieldProps,
labelProps,
wrapperProps
),
email: withCustomStyles(
components.email,
fieldProps,
labelProps,
wrapperProps
),
textarea: withCustomStyles(
components.textarea,
fieldProps,
labelProps,
wrapperProps
),
select: withCustomStyles(
components.select,
fieldProps,
labelProps,
wrapperProps
),
webform_actions: withCustomStyles(
components.webform_actions,
{},
{},
{ className: classNames("my-4", "space-x-4") }
),
button: withCustomStyles(WebformButton, buttonProps, {}, {}),
}}
/>
</div>
<p>
<Link href="/" passHref>
<a>Go back</a>
</Link>
</p>
</article>
</div>
</>
)
}
export async function getStaticProps(): Promise<
GetStaticPropsResult<WebformPageProps>
> {
return {
props: {
webform: await resolveWebformContent("contact", drupal),
},
}
}