clubs channel slacks (#160)

* Update join-form.js

* Update join-form.js

* Update use-form.js

* Update join.js

* Update use-form.js
This commit is contained in:
Sam Poder 2021-08-01 15:30:33 +08:00 committed by GitHub
parent 1a97202725
commit ed34fff97f
3 changed files with 6 additions and 3 deletions

View file

@ -1,9 +1,11 @@
import { Card, Label, Input, Checkbox, Textarea } from 'theme-ui'
import { useRouter } from 'next/router'
import useForm from '../../lib/use-form'
import Submit from '../submit'
const JoinForm = ({ sx = {} }) => {
const { status, formProps, useField } = useForm('/api/join/')
const router = useRouter()
const { status, formProps, useField } = useForm('/api/join/', null, { clearOnSubmit: 5000, method: 'POST', initData: router.query.club ? {club: router.query.club} : {} })
return (
<Card sx={{ maxWidth: 'narrow', mx: 'auto', label: { mb: 3 }, ...sx }}>

View file

@ -3,7 +3,7 @@ import { useState, useEffect } from 'react'
const useForm = (
submitURL = '/',
callback,
options = { clearOnSubmit: 5000, method: 'POST' }
options = { clearOnSubmit: 5000, method: 'POST', initData: {} }
) => {
const [status, setStatus] = useState('default')
const [data, setData] = useState({})
@ -12,7 +12,7 @@ const useForm = (
const onFieldChange = (e, name, type) => {
e.persist()
const value = e.target[type === 'checkbox' ? 'checked' : 'value']
setData(data => ({ ...data, [name]: value }))
setData(data => ({ ...data, ...options.initData, [name]: value }))
}
useEffect(() => {

View file

@ -47,6 +47,7 @@ export default async (req, res) => {
Student: data.teen,
Reason: data.reason,
Invited: true,
Club: data.club ? data.club : '',
IP: req.headers['x-forwarded-for'] || req.socket.remoteAddress
})