Auto Continent (#425)

* A small test

* continental 🌴

* Hmm

* Update use-form.js

* Update _middleware.js

* Update _middleware.js

* I think I got it!

* Try using rewrite

* Update _middleware.js
This commit is contained in:
Sam Poder 2022-04-17 15:50:00 +08:00 committed by GitHub
parent 7dacf9b191
commit 22dd273557
6 changed files with 117 additions and 18 deletions

View file

@ -8,13 +8,10 @@ const JoinForm = ({ sx = {} }) => {
const { status, formProps, useField } = useForm('/api/join/', null, {
clearOnSubmit: 5000,
method: 'POST',
initData: router.query.c
? { club: router.query.c }
: router.query['C']
? { club: router.query['C'] }
initData: router.query.continent
? { continent: router.query.continent }
: {}
})
return (
<Card sx={{ maxWidth: 'narrow', mx: 'auto', label: { mb: 3 }, ...sx }}>
<form {...formProps}>

View file

@ -6,7 +6,7 @@ const useForm = (
options = { clearOnSubmit: 5000, method: 'POST', initData: {} }
) => {
const [status, setStatus] = useState('default')
const [data, setData] = useState({})
const [data, setData] = useState({...options.initData})
const [touched, setTouched] = useState({})
const onFieldChange = (e, name, type) => {
@ -23,7 +23,7 @@ const useForm = (
const checkbox = type === 'checkbox'
const empty = checkbox ? false : ''
const onChange = e => onFieldChange(e, name, type)
const value = data[name]
const value = data[name] || options.initData[name]
return {
name,
type: name === 'email' ? 'email' : type,

View file

@ -24,6 +24,7 @@
"airtable-plus": "^1.0.4",
"animated-value": "^0.2.4",
"animejs": "^3.2.1",
"country-list-js": "^3.1.7",
"globby": "^11.0.4",
"lodash": "^4.17.21",
"next": "^12.1.4",
@ -43,7 +44,7 @@
"turndown": "^7.1.1"
},
"devDependencies": {
"eslint-config-next": "12.1.4",
"eslint": "8.13.0"
"eslint": "8.13.0",
"eslint-config-next": "12.1.4"
}
}

View file

@ -0,0 +1,14 @@
import { NextResponse } from 'next/server'
import country from 'country-list-js';
export function middleware(req) {
let url = req.nextUrl
if(!url.searchParams.get("continent")){
let continent = country.findByIso2(req.geo.country || "AU").continent
if(continent == "Oceania"){
continent = "Australia"
}
url.searchParams.set("continent", continent)
return NextResponse.redirect(url)
}
}

View file

@ -3,15 +3,15 @@ import { keyframes } from '@emotion/react'
import Head from 'next/head'
import NextLink from 'next/link'
import Meta from '@hackclub/meta'
import Nav from '../components/nav'
import ForceTheme from '../components/force-theme'
import Icon from '../components/icon'
import Stat from '../components/stat'
import Footer from '../components/footer'
import Header from '../components/slack/header'
import SlackEvents from '../components/slack/slack-events'
import { getCount } from '../pages/api/channels/count-to-a-million'
import { formatted, thousands } from '../lib/members'
import Nav from '../../components/nav'
import ForceTheme from '../../components/force-theme'
import Icon from '../../components/icon'
import Stat from '../../components/stat'
import Footer from '../../components/footer'
import Header from '../../components/slack/header'
import SlackEvents from '../../components/slack/slack-events'
import { getCount } from '../../pages/api/channels/count-to-a-million'
import { formatted, thousands } from '../../lib/members'
const zoomSlide = keyframes({
from: { backgroundPosition: '-32px bottom' },

View file

@ -1073,6 +1073,11 @@ ansi-styles@^4.1.0:
dependencies:
color-convert "^2.0.1"
arg@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.0.tgz#583c518199419e0037abb74062c37f8519e575f0"
integrity sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==
argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
@ -1243,6 +1248,11 @@ buffer-equal-constant-time@1.0.1:
resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819"
integrity sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=
bytes@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=
call-bind@^1.0.0, call-bind@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz"
@ -1368,6 +1378,11 @@ concat-map@0.0.1:
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
content-type@1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==
convert-source-map@^1.5.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.8.0.tgz#f3373c32d21b4d780dd8004514684fb791ca4369"
@ -1403,6 +1418,13 @@ cosmiconfig@^6.0.0:
path-type "^4.0.0"
yaml "^1.7.2"
country-list-js@^3.1.7:
version "3.1.7"
resolved "https://registry.yarnpkg.com/country-list-js/-/country-list-js-3.1.7.tgz#b6821872a4fc83059d595b0d62d0b5df0569cb51"
integrity sha512-/P+5kntwSWOX3qzGn+IYrRPlq7PyM8MJbO8nDX23NMeEAyfovheiFrMDMKcfc5LU2oJZ/R942ZltiPuOLHmkCw==
dependencies:
micro "^9.3.3"
cross-spawn@^7.0.2:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
@ -1477,6 +1499,11 @@ delayed-stream@~1.0.0:
resolved "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz"
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=
depd@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.1.tgz#5783b4e1c459f06fa5ca27f991f3d06e7a310359"
integrity sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=
deprecation@^2.0.0, deprecation@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919"
@ -2174,6 +2201,16 @@ html-void-elements@^1.0.0:
resolved "https://registry.npmjs.org/html-void-elements/-/html-void-elements-1.0.5.tgz"
integrity sha512-uE/TxKuyNIcx44cIWnjr/rfIATDH7ZaOMmstu0CwhFG1Dunhlp4OC6/NMbhiwoq5BpW0ubi303qnEk/PZj614w==
http-errors@1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.2.tgz#0a002cc85707192a7e7946ceedc11155f60ec736"
integrity sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=
dependencies:
depd "1.1.1"
inherits "2.0.3"
setprototypeof "1.0.3"
statuses ">= 1.3.1 < 2"
http-signature@~1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz"
@ -2183,6 +2220,11 @@ http-signature@~1.2.0:
jsprim "^1.2.2"
sshpk "^1.7.0"
iconv-lite@0.4.19:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
integrity sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==
ignore@^5.1.4, ignore@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
@ -2214,6 +2256,11 @@ inherits@2, inherits@^2.0.0:
resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
inherits@2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
inline-style-parser@0.1.1:
version "0.1.1"
resolved "https://registry.npmjs.org/inline-style-parser/-/inline-style-parser-0.1.1.tgz"
@ -2364,6 +2411,11 @@ is-shared-array-buffer@^1.0.1:
resolved "https://registry.yarnpkg.com/is-shared-array-buffer/-/is-shared-array-buffer-1.0.1.tgz#97b0c85fbdacb59c9c446fe653b82cf2b5b7cfe6"
integrity sha512-IU0NmyknYZN0rChcKhRO1X8LYz5Isj/Fsqh8NJOSf+N/hCOTwy29F32Ik7a+QszE63IdvmwdTPDd6cZ5pg4cwA==
is-stream@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ=
is-string@^1.0.5:
version "1.0.5"
resolved "https://registry.npmjs.org/is-string/-/is-string-1.0.5.tgz"
@ -2686,6 +2738,16 @@ merge2@^1.3.0:
resolved "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
micro@^9.3.3:
version "9.3.4"
resolved "https://registry.yarnpkg.com/micro/-/micro-9.3.4.tgz#745a494e53c8916f64fb6a729f8cbf2a506b35ad"
integrity sha512-smz9naZwTG7qaFnEZ2vn248YZq9XR+XoOH3auieZbkhDL4xLOxiE+KqG8qqnBeKfXA9c1uEFGCxPN1D+nT6N7w==
dependencies:
arg "4.1.0"
content-type "1.0.4"
is-stream "1.1.0"
raw-body "2.3.2"
micromatch@^4.0.2:
version "4.0.2"
resolved "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz"
@ -3059,6 +3121,16 @@ quick-lru@^1.0.0:
resolved "https://registry.npmjs.org/quick-lru/-/quick-lru-1.1.0.tgz"
integrity sha1-Q2CxfGETatOAeDl/8RQW4Ybc+7g=
raw-body@2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.2.tgz#bcd60c77d3eb93cde0050295c3f379389bc88f89"
integrity sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=
dependencies:
bytes "3.0.0"
http-errors "1.6.2"
iconv-lite "0.4.19"
unpipe "1.0.0"
react-dom@^17.0.2:
version "17.0.2"
resolved "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz"
@ -3313,6 +3385,11 @@ semver@^7.3.5:
dependencies:
lru-cache "^6.0.0"
setprototypeof@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.0.3.tgz#66567e37043eeb4f04d91bd658c0cbefb55b8e04"
integrity sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=
shebang-command@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
@ -3374,6 +3451,11 @@ state-toggle@^1.0.0:
resolved "https://registry.npmjs.org/state-toggle/-/state-toggle-1.0.3.tgz"
integrity sha512-d/5Z4/2iiCnHw6Xzghyhb+GcmF89bxwgXG60wjIiZaxnymbyOmI8Hk4VqHXiVVp6u2ysaskFfXg3ekCj4WNftQ==
"statuses@>= 1.3.1 < 2":
version "1.5.0"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=
string.prototype.matchall@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.6.tgz#5abb5dabc94c7b0ea2380f65ba610b3a544b15fa"
@ -3717,6 +3799,11 @@ universal-user-agent@^6.0.0:
resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee"
integrity sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==
unpipe@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=
uri-js@^4.2.2:
version "4.4.1"
resolved "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz"