From 03a00a24d5f336589907058b8afd2aa84cc479c8 Mon Sep 17 00:00:00 2001 From: HARUMI JANG Date: Tue, 26 Jul 2022 18:00:59 -0400 Subject: [PATCH 01/40] GET --- WEBFORMS.md | 16 ++++++ .../components/node--article.tsx | 50 ++++++++++++++++++- starters/basic-starter/pages/[...slug].tsx | 37 +++++++++++++- 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 WEBFORMS.md diff --git a/WEBFORMS.md b/WEBFORMS.md new file mode 100644 index 00000000..82d386b1 --- /dev/null +++ b/WEBFORMS.md @@ -0,0 +1,16 @@ +How to set up Webform REST on ACMS + +1. Download the Webform and Webform REST modules +

+2. Enable REST resources "Webform Submit", "Webform Elements", "Webform Submission" on /admin/config/services/rest +

+3. Set permissions `/admin/people/permissions#module-rest` for RESTful Web Services and check Anonymous User for the Webform related permissions to avoid dealing with auth/headers for now. +

+4. Create a new webform if you have not already `/admin/structure/webform` +

+5. Go to article content type and create a webform field on `/admin/structure/types/manage/article/fields` +

+6. Add a webform to one of the article nodes. +

+7. Now you should be able to make requests to the API. ex) GET`/webform_rest/{webform_id}/fields?_format=json` + diff --git a/starters/basic-starter/components/node--article.tsx b/starters/basic-starter/components/node--article.tsx index 7505acc5..ca55f707 100644 --- a/starters/basic-starter/components/node--article.tsx +++ b/starters/basic-starter/components/node--article.tsx @@ -3,13 +3,61 @@ import Link from 'next/link'; import { formatDate } from 'lib/format-date'; import { MediaImage } from 'components/media--image'; import { FormattedText } from 'components/formatted-text'; +import React, { useState } from 'react'; +// import { submitForm } from '../pages/[...slug]'; -export function NodeArticle({ node, ...props }) { +const initialValues = { + name: '', + email: '', + subject: '', + message: '', +}; + +export function NodeArticle({ node, additionalContent, ...props }) { + const [values, setValues] = useState(initialValues); + + function handleInputChange( + e: + | React.ChangeEvent + | React.ChangeEvent, + ) { + const { name, value } = e.target; + setValues({ + ...values, + [name]: value, + }); + console.log(e.target); + } return (

{node.title}

+

Contact

+ + + +