-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c6ef17
commit aa71e44
Showing
2 changed files
with
54 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,56 @@ | ||
'use client' | ||
"use client"; | ||
|
||
import { Fragment } from 'react'; | ||
import Adult from './adult'; | ||
import Child from './child'; | ||
import styles from './styles.module.css' | ||
import { SubmitButton } from './submit'; | ||
import { submit } from '@app/actions' | ||
import type { Guest, NotionPerson, Person } from '@ts/people'; | ||
import { Fragment } from "react"; | ||
import Adult from "./adult"; | ||
import Child from "./child"; | ||
import styles from "./styles.module.css"; | ||
import { SubmitButton } from "./submit"; | ||
import { submit } from "@app/actions"; | ||
import type { Guest, NotionPerson, Person } from "@ts/people"; | ||
|
||
type FormTypes = { | ||
people: NotionPerson[] | ||
guest: Guest | ||
closeModal: () => void | ||
open: boolean | ||
} | ||
people: NotionPerson[]; | ||
guest: Guest; | ||
closeModal: () => void; | ||
open: boolean; | ||
}; | ||
|
||
const RSVPForm = ({ people, closeModal, guest, open }: FormTypes) => | ||
{ | ||
const handleSubmit = submit.bind(null, guest.id) | ||
const RSVPForm = ({ people, closeModal, guest, open }: FormTypes) => { | ||
const handleSubmit = submit.bind(null, guest.id); | ||
|
||
return ( | ||
console.log({ people }); | ||
|
||
return ( | ||
<form action={handleSubmit} className={styles.form} data-open={open}> | ||
{people?.toSorted((a, b) => Number(a.properties.Child.checkbox) - Number(b.properties.Child.checkbox)).map(({ id, properties }) => | ||
{ | ||
const data: Person = { | ||
id: id, | ||
name: { | ||
full: properties.Name.title?.[0]?.plain_text, | ||
first: properties['First Name'].rich_text?.[0]?.plain_text, | ||
last: properties['Last Name'].rich_text?.[0]?.plain_text | ||
}, | ||
attending: properties.Attending?.select?.name, | ||
meal: properties.Meal?.select?.name, | ||
dietary: properties['Dietary Requirements']?.rich_text?.[0]?.text.content, | ||
age: parseInt(properties.Age?.rich_text?.[0]?.plain_text), | ||
child: properties.Child?.checkbox, | ||
song: properties['Song']?.rich_text?.[0]?.text.content, | ||
} | ||
|
||
return ( | ||
<Fragment key={data.id}> | ||
{data.child && <Child {...data} />} | ||
|
||
{!data.child && <Adult {...data} />} | ||
</Fragment> | ||
) | ||
})} | ||
{people | ||
?.toSorted((a, b) => Number(a?.properties?.Child?.checkbox) - Number(b?.properties?.Child?.checkbox)) | ||
?.map(({ id, properties }) => { | ||
const data: Person = { | ||
id: id, | ||
name: { | ||
full: properties.Name.title?.[0]?.plain_text, | ||
first: properties["First Name"].rich_text?.[0]?.plain_text, | ||
last: properties["Last Name"].rich_text?.[0]?.plain_text, | ||
}, | ||
attending: properties.Attending?.select?.name, | ||
meal: properties.Meal?.select?.name, | ||
dietary: properties["Dietary Requirements"]?.rich_text?.[0]?.text.content, | ||
age: parseInt(properties.Age?.rich_text?.[0]?.plain_text), | ||
child: properties.Child?.checkbox, | ||
song: properties["Song"]?.rich_text?.[0]?.text.content, | ||
}; | ||
|
||
return ( | ||
<Fragment key={data.id}> | ||
{data.child && <Child {...data} />} | ||
|
||
{!data.child && <Adult {...data} />} | ||
</Fragment> | ||
); | ||
})} | ||
<SubmitButton closeModal={closeModal} /> | ||
</form> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
export default RSVPForm | ||
export default RSVPForm; |