Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I32 incident and vet buttons and forms #157

Merged
merged 25 commits into from Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c2a2e0d
initial form adjustments
RadioArsenic Dec 10, 2022
5a932ec
Fix form deactivation
zachpmanson Dec 10, 2022
1157716
Broken
zachpmanson Dec 17, 2022
6984a86
Fix it
zachpmanson Dec 17, 2022
34630f4
Add visit context
zachpmanson Dec 17, 2022
de8f040
added incident form
RadioArsenic Dec 17, 2022
2604d24
got rid of old incident form
RadioArsenic Dec 17, 2022
397735a
Resolve merge
zachpmanson Dec 17, 2022
53e7f4b
resolve merge error
QuantumApostle07 Dec 17, 2022
f5cf496
Vet Concern Resolution
QuantumApostle07 Dec 17, 2022
dbb7f2a
added in default values for user info
RadioArsenic Dec 17, 2022
5cb1ae9
Merge branch 'i32-incident-and-vet-buttons-and-forms' of https://gith…
RadioArsenic Dec 17, 2022
5356010
Merge branch 'main' into i32-incident-and-vet-buttons-and-forms
zachpmanson Dec 17, 2022
2b393ba
Move to using routes
zachpmanson Dec 17, 2022
0601e44
Add new forms
zachpmanson Dec 17, 2022
3ff4b9a
renamed vet page
RadioArsenic Dec 17, 2022
c8eb072
Merge branch 'main' into i32-incident-and-vet-buttons-and-forms
zachpmanson Jan 6, 2023
d729625
Compatibility with main
zachpmanson Jan 6, 2023
b9f8f54
Update XMark to hericons version
zachpmanson Jan 6, 2023
4e90f6a
simple fixes (lint, capitalisation, removed 'any')
RadioArsenic Jan 7, 2023
ba3ca11
fixed the button overlap bug
RadioArsenic Jan 8, 2023
61a3076
Make userid required
zachpmanson Jan 10, 2023
0437837
Autofill pets name
zachpmanson Jan 10, 2023
c71bec8
Autofill pets name
zachpmanson Jan 10, 2023
dcfb5f2
Change how buttons link
zachpmanson Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/components/Visit/readvisitinstance.tsx
@@ -1,4 +1,6 @@
import Button from '@/components/UI/button'
scratchclaggy marked this conversation as resolved.
Show resolved Hide resolved
import { Duration, Visit } from '@/types/types'
import Link from 'next/link'

export const formatDuration = (duration: Duration) => {
const d = `${duration.hours} ${duration.hours === 1 ? 'hr' : 'hrs'} ${
Expand All @@ -22,18 +24,29 @@ const VisitInfo = ({
notes = ''
}: VisitInfoProps) => {
return (
<div
className='justify-between overflow-hidden text-sm transition-all duration-300'
style={{ maxHeight: isOpen ? '100vh' : '0' }}
>
<p>Visit Type: {type}</p>
<p>Pet(s): {petNames}</p>
<p>Duration: {formatDuration(duration)}</p>
<p>Walk Distance: {walkDist.toFixed(3)} km</p>
<p>Commute Distance: {commuteDist.toFixed(1)} km</p>
<p>Commute Method: {commuteMethod}</p>
<p>Notes: {notes}</p>
</div>
<>
<div
className={`justify-between overflow-hidden text-sm transition-all duration-300 ${
isOpen ? 'max-h-screen' : 'max-h-0'
}`}
>
<p>Visit Type: {type}</p>
<p>Pet(s): {petNames}</p>
<p>Duration: {formatDuration(duration)}</p>
<p>Walk Distance: {walkDist.toFixed(3)} km</p>
<p>Commute Distance: {commuteDist.toFixed(1)} km</p>
<p>Commute Method: {commuteMethod}</p>
<p>Notes: {notes}</p>
<div className='my-2 flex justify-center gap-2'>
zachpmanson marked this conversation as resolved.
Show resolved Hide resolved
<Link href='/visit/incident'>
<Button size='medium'>Report incident</Button>
scratchclaggy marked this conversation as resolved.
Show resolved Hide resolved
</Link>
<Link href='/visit/vet'>
zachpmanson marked this conversation as resolved.
Show resolved Hide resolved
<Button size='medium'>Register Vet Concern</Button>
</Link>
</div>
</div>
</>
)
}

Expand Down
36 changes: 18 additions & 18 deletions src/components/Visit/visitinstance.tsx
@@ -1,6 +1,5 @@
import { useState } from 'react'
import { ChevronDownIcon } from '@heroicons/react/24/outline'
import { Timestamp } from 'firebase/firestore'
import { useState } from 'react'

import { Visit } from '@/types/types'
import { humanizeTimestamp } from '@/utils'
Expand All @@ -15,27 +14,28 @@ const VisitInstance = (props: Visit) => {

return (
<div className='m-2 flex flex-col rounded-xl bg-gray-50 p-4 drop-shadow-default'>
<div className='flex content-center justify-between'>
<div style={{ fontWeight: isOpen ? 400 : 700 }}>
<div className='flex justify-between'>
<div className='font-bold'>
<p className='font-bold text-primary'>
{humanizeTimestamp(props.startTime || new Timestamp(0, 0))}
{humanizeTimestamp(props.startTime)}
</p>
<p className='text-sm'>{props.clientName || 'N/A'}</p>
<p className='text-sm'>{props.clientName}</p>
</div>
<div>
<ChevronDownIcon
className='h-7 w-7 cursor-pointer self-center text-primary transition-transform duration-300'
style={{
rotate: !isOpen ? '0deg' : '180deg',
transitionProperty: 'rotate'
}}
onClick={() => {
setIsOpen(!isOpen)
}}
/>
</div>

<ChevronDownIcon
className='h-7 w-7 cursor-pointer self-center text-primary transition-transform duration-300'
style={{
rotate: !isOpen ? '0deg' : '180deg',
transitionProperty: 'rotate'
}}
onClick={() => {
setIsOpen(!isOpen)
}}
/>
</div>
<VisitInfo {...props} isOpen={isOpen} />
{isOpen && <EditButton id={props.docId} />}
<VisitInfo {...props} isOpen={isOpen} />
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Visit/visitlist.tsx
Expand Up @@ -26,7 +26,7 @@ export const VisitList = (props: VisitListProps) => {
{visits && visits.length !== 0 ? (
visits
.filter(searchFilter)
.map((visit) =>
.map((visit: any) =>
scratchclaggy marked this conversation as resolved.
Show resolved Hide resolved
visit.docId ? <VisitInstance key={visit.docId} {...visit} /> : null
)
) : (
Expand Down
127 changes: 127 additions & 0 deletions src/pages/visit/incident.tsx
@@ -0,0 +1,127 @@
import { XMarkIcon } from '@heroicons/react/24/solid'
import { FormEvent, useState } from 'react'

import { useAuth } from '@/context/Firebase/Auth/context'
import { IncidentForm } from '@/types/types'

import { withProtected } from '@/components/PrivateRoute'
import Button from '@/components/UI/button'
import FormField from '@/components/Visit/formfield'
import Link from 'next/link'
import { useRouter } from 'next/router'

const IncidentForm = () => {
const { currentUser } = useAuth()
const [userName, setUserName] = useState(
currentUser?.displayName ? currentUser?.displayName : ''
)
const [email, setEmail] = useState(
currentUser?.email ? currentUser?.email : ''
)
const [petName, setPetName] = useState('')
zachpmanson marked this conversation as resolved.
Show resolved Hide resolved
const [time, setTime] = useState('') //check issue comments for date/time
const [notes, setNotes] = useState('')
const router = useRouter()

const handleSubmit = (click: FormEvent<HTMLFormElement>) => {
click.preventDefault()
const data: IncidentForm = {
userID: currentUser?.uid,
userName: userName,
email: email,
petName: petName,
time: time,
details: notes
}
console.log(data)
router.push('/visit')
}

const isSubmitEnabled = () => {
return currentUser?.uid && userName && email && petName && time && notes
}

return (
<div className='z-50 p-4'>
<>
<div className='fixed right-5 top-4 z-[100] h-10 w-10 rounded-full bg-primary p-1 drop-shadow-default'>
<Link href='/visit'>
<button>
<XMarkIcon className='h-full w-full text-white' />
</button>
</Link>
</div>

<div className='border-b-2 border-primary py-3 pt-10'>
<h1 className='pl-2 text-2xl font-bold'>Add Your Incident</h1>
</div>

<form className='pt-3' onSubmit={handleSubmit}>
<table className='container mx-auto table-fixed'>
<tbody>
<tr>
<td>
<FormField
id='userNameInput'
type='text'
placeholder={userName}
label='Name'
isRequired={false}
onChange={(event) => setUserName(event.target.value)}
/>
</td>
<td>
<FormField
id='emailInput'
type='email'
placeholder={email}
label='Email'
isRequired={false}
onChange={(event) => setEmail(event.target.value)}
/>
</td>
</tr>
<tr>
<td>
<FormField
id='petNameInput'
type='text'
placeholder='Pet name'
label='Pet Name'
isRequired={false}
onChange={(event) => setPetName(event.target.value)}
/>
</td>
<td>
<FormField
id='timeInput'
type='dateTime-local'
placeholder='Time'
label='Date & Time'
isRequired={false}
onChange={(event) => setTime(event.target.value)}
/>
</td>
</tr>
</tbody>
</table>
<FormField
id='notesInput'
type='textarea'
placeholder='Add notes here'
label='Description'
isRequired={false}
onChange={(event) => setNotes(event.target.value)}
/>
<div className='mx-auto my-2 flex flex-col p-1 '>
<Button type='submit' disabled={!isSubmitEnabled()}>
Submit
</Button>
</div>
</form>
</>
</div>
)
}

export default withProtected(IncidentForm)
136 changes: 136 additions & 0 deletions src/pages/visit/vet.tsx
@@ -0,0 +1,136 @@
import { FormEvent, useState } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { XMarkIcon } from '@heroicons/react/24/solid'

import { withProtected } from '@/components/PrivateRoute'
import Button from '@/components/UI/button'
import FormField from '@/components/Visit/formfield'
import { useAuth } from '@/context/Firebase/Auth/context'
import { VetConcernsForm } from '@/types/types'

const VetForm = () => {
const { currentUser } = useAuth()
const [userName, setUserName] = useState(
currentUser?.displayName ? currentUser?.displayName : ''
)
const [email, setEmail] = useState(
currentUser?.email ? currentUser?.email : ''
)
const [petName, setPetName] = useState('')
zachpmanson marked this conversation as resolved.
Show resolved Hide resolved
const [vetName, setVetName] = useState('')
const [time, setTime] = useState('') //check issue comments for date/time
const [notes, setNotes] = useState('')
const router = useRouter()

const handleSubmit = (click: FormEvent<HTMLFormElement>) => {
click.preventDefault()
const data: VetConcernsForm = {
userID: currentUser?.uid,
userName: userName,
email: email,
petName: petName,
vetName: vetName,
time: time,
details: notes
}
console.log(data)
router.push('/visit')
}

const isSubmitEnabled = () => {
return currentUser?.uid && userName && email && petName && time && notes
}

return (
<div className='z-50 p-4'>
<>
<div className='fixed right-5 top-4 z-[100] h-10 w-10 rounded-full bg-primary p-1 drop-shadow-default'>
<Link href='/visit'>
<button>
<XMarkIcon className='h-full w-full text-white' />
</button>
</Link>
</div>

<div className='border-b-2 border-primary py-3 pt-10'>
<h1 className='pl-2 text-2xl font-bold'>Register a Vet Concern</h1>
</div>

<form className='pt-3' onSubmit={handleSubmit}>
<table className='container mx-auto table-fixed'>
<tbody>
<tr>
<td>
<FormField
id='userNameInput'
type='text'
placeholder={userName}
label='Name'
isRequired={false}
onChange={(event) => setUserName(event.target.value)}
/>
</td>
<td>
<FormField
id='emailInput'
type='email'
placeholder={email}
label='Email'
isRequired={false}
onChange={(event) => setEmail(event.target.value)}
/>
</td>
</tr>
<tr>
<td>
<FormField
id='petNameInput'
type='text'
placeholder='Pet name'
label='Pet Name'
isRequired={false}
onChange={(event) => setPetName(event.target.value)}
/>
</td>
<td>
<FormField
id='vetNameInput'
type='text'
placeholder='Vet name'
label='Vet Name'
isRequired={false}
onChange={(event) => setVetName(event.target.value)}
/>
</td>
</tr>
</tbody>
</table>
<FormField
id='timeInput'
type='dateTime-local'
placeholder='Time'
label='Date & Time'
isRequired={false}
onChange={(event) => setTime(event.target.value)}
/>
<FormField
id='notesInput'
type='textarea'
placeholder='Add notes here'
label='Description'
isRequired={false}
onChange={(event) => setNotes(event.target.value)}
/>
<div className='mx-auto my-2 flex flex-col p-1 '>
<Button type='submit' disabled={!isSubmitEnabled()}>
Submit
</Button>
</div>
</form>
</>
</div>
)
}

export default withProtected(VetForm)
19 changes: 19 additions & 0 deletions src/types/types.ts
Expand Up @@ -47,3 +47,22 @@ export type Duration = {
hours: number
minutes: number
}

export type IncidentForm = {
userID?: string
zachpmanson marked this conversation as resolved.
Show resolved Hide resolved
userName: string | null | undefined
email: string | null | undefined
petName: string
time: string
details: string
}

export type VetConcernsForm = {
userID?: string
userName: string
email: string
petName: string
vetName: string
time: string
details: string
}