mirror of
https://github.com/System-End/site.git
synced 2026-04-19 22:05:11 +00:00
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:
parent
1a97202725
commit
ed34fff97f
3 changed files with 6 additions and 3 deletions
|
|
@ -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 }}>
|
||||
|
|
|
|||
|
|
@ -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(() => {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue