Skip to content

Commit

Permalink
Link applications to space schedule (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucieo authored Feb 22, 2024
1 parent dd297a2 commit 0ae6c04
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HStack, Select } from '@chakra-ui/react'
import { useRouter } from 'next/router'
import { useEffect, useMemo, useState } from 'react'
import SelectMenu from '~components/Account/Application/Place/Selectors/SelectMenu'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import { ROUTE_ACCOUNT_APPLICATIONS } from '~constants'
import { Espace } from '~typings/api'
Expand All @@ -11,25 +10,24 @@ const ApplicationSelector = ({ places }: { places: Espace[] }) => {
const { currentCampaign } = useCampaignContext()

const router = useRouter()
const { queryEspace, queryDisponibility } = router.query
const {
espace: queryEspace,
disponibility: queryDisponibility,
} = router.query
const [espace, setEspace] = useState(queryEspace)
const [disponibility, setDisponibility] = useState(queryDisponibility)

useEffect(() => {
if (queryEspace) {
setEspace(queryEspace)
}
}, [queryEspace])

const initState = () => {
const espace = places?.[0]?.id
const espace = queryEspace || places?.[0]?.id
const disponibility = places?.[0]?.id
setEspace(espace)
setDisponibility(disponibility)
router.push({
pathname: router.pathname,
query: { espace, disponibility },
})
if (!queryEspace || !queryDisponibility) {
router.push({
pathname: router.pathname,
query: { espace, disponibility },
})
}
}

useEffect(() => {
Expand All @@ -56,22 +54,6 @@ const ApplicationSelector = ({ places }: { places: Espace[] }) => {

return (
<HStack paddingBottom={4}>
<SelectMenu
options={places.map((place) => ({
value: place.id,
label: place.name,
}))}
onChange={(data) => {
console.log(data)

// const disponibility = getDispoOptions(e.target.value)[0]?.id
// router.push({
// pathname: router.pathname,
// query: { espace: e.target.value, disponibility },
// })
}}
value={espace as string}
/>
<Select
width="auto"
borderRadius="18px"
Expand Down
30 changes: 14 additions & 16 deletions web/components/Campaign/Places/Admin/CampaignScheduleInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import React, { useContext } from 'react'
import {
Flex,
Box,
Text,
Button,
useBreakpointValue,
VStack,
} from '@chakra-ui/react'
import { Box, Text, Button, useBreakpointValue, VStack } from '@chakra-ui/react'
import { useTranslation } from 'next-i18next'
import { Espace } from '~typings/api'
import PlacesAdminCampaignHelper from '~components/Campaign/Places/Admin/PlacesAdminCampaignHelper'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import { format } from '~utils/date'
import ScheduleContext from '~components/Account/Place/ScheduleContext'
import ScheduleDelete from '~components/Account/Place/ScheduleDelete'
import Link from 'next/link'
import Link from '~components/Link'
import { ROUTE_ACCOUNT_APPLICATIONS } from '~constants'

interface Props {
place: Espace
Expand All @@ -27,7 +21,7 @@ const CampaignScheduleInfo = ({ place, showForm }: Props) => {
const campaignDispo = place?.disponibilities?.filter(
//@ts-expect-error
(d) => d.campaign === currentCampaign?.id,
)?.length
)
const isMobile = useBreakpointValue({ base: true, sm: false })
const { eventsIdToDelete } = useContext(ScheduleContext)

Expand Down Expand Up @@ -57,8 +51,8 @@ const CampaignScheduleInfo = ({ place, showForm }: Props) => {
<Box width="100%">
<Text fontFamily="mabry medium" fontSize="3xl" lineHeight="1">
{currentCampaign?.mode === 'disponibilities'
? `${campaignDispo}/${currentCampaign?.disponibilities_max}`
: campaignDispo}
? `${campaignDispo?.length}/${currentCampaign?.disponibilities_max}`
: campaignDispo?.length}
</Text>
<Text>
{currentCampaign?.mode === 'disponibilities'
Expand All @@ -68,7 +62,7 @@ const CampaignScheduleInfo = ({ place, showForm }: Props) => {
)
: t(
`campaign.helpers.applications.schedule.${
campaignDispo <= 1
campaignDispo?.length <= 1
? 'open_applications_one'
: 'open_applications_many'
}`,
Expand All @@ -81,21 +75,25 @@ const CampaignScheduleInfo = ({ place, showForm }: Props) => {
alignSelf="flex-start"
mt={6}
onClick={showForm}
disabled={campaignDispo === currentCampaign?.disponibilities_max}
disabled={
campaignDispo?.length === currentCampaign?.disponibilities_max
}
>
{isMobile ? t(`list.add`) : t(`schedule.add`)}
</Button>
) : (
) : campaignDispo?.length > 0 ? (
<Button
size="lg"
alignSelf="flex-start"
mt={6}
variant="outline"
colorScheme="blue"
as={Link}
href={`${ROUTE_ACCOUNT_APPLICATIONS}?espace=${place.id}&disponibility=${campaignDispo[0]?.id}`}
>
{t('campaign.helpers.applications.schedule.see_applications')}
</Button>
)}
) : null}
</VStack>
)
}
Expand Down

0 comments on commit 0ae6c04

Please sign in to comment.