Skip to content

Commit

Permalink
Merge pull request #126 from AtelierdeParis/feat/various-improvements
Browse files Browse the repository at this point in the history
feat: various improvements
  • Loading branch information
baptadn authored Mar 11, 2024
2 parents 8c2102c + 93c5c1b commit 041cbd1
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"x-generation-date": "03/07/2024 4:37:03 PM"
"x-generation-date": "03/10/2024 10:56:56 PM"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down
3 changes: 2 additions & 1 deletion web/components/Account/AccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ const AccountMenu = ({ user }: { user: UsersPermissionsUser }) => {
(user?.type === 'place' &&
placeCampaigns?.length &&
applications?.length) ||
(user?.type === 'company' && currentCampaign)
(user?.type === 'company' && currentCampaign && currentCampaign.mode !== "closed")


const displayMenu = ({ title, items, translationParams = {} }) => {
const isDisactivated = !isComplete && title === 'dashboard'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const ApplicationCompanyList = ({ applications = [] }: Props) => {
query?.disponibility as string,
])
queryClient.refetchQueries(['me'])
onClose()
} catch (e) {
errorToast(t('company.delete_error'))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { Box, Button } from '@chakra-ui/react'
import { useTranslation } from 'next-i18next'
import { useRouter } from 'next/router'
import { useState } from 'react'
import { useMyApplications } from '~hooks/useMyApplications'
import useSelectedCampaign from '~hooks/useSelectedCampaign'
import useToast from '~hooks/useToast'
import { handleDisponibilityDownload } from '~utils/pdf'

const ApplicationDownloadAll = () => {
const { selectedCampaign } = useSelectedCampaign()
const { errorToast } = useToast()
const { t } = useTranslation('application')
const { query } = useRouter()
const [isDownloading, setIsDownloading] = useState(false)

const { data: applications, isLoading, isFetching } = useMyApplications({
name: ['myApplications', query?.disponibility as string],
searchParams: { ...query, _sort: 'company.structureName:asc' },
Expand All @@ -28,31 +24,18 @@ const ApplicationDownloadAll = () => {
return (
<Box p={{ base: 2, sm: 4 }}>
<Button
as="a"
href={`/api/pdfs/all/${applications?.[0]?.disponibility.id}`}
target='_blank'
colorScheme={selectedCampaign?.mode === 'closed' ? 'gray' : 'blue'}
backgroundColor={
selectedCampaign?.mode === 'closed' ? 'gray.700' : undefined
}
color={'white'}
size="lg"
isLoading={isLoading || isFetching || isDownloading}
isLoading={isLoading || isFetching}
isDisabled={!applications?.length}
isFullWidth
onClick={async () => {
setIsDownloading(true)
try {
await handleDisponibilityDownload({
//@ts-expect-error
disponibility: applications[0]?.disponibility,
onError: () => errorToast(t('error')),
campaign: selectedCampaign,
})
} catch (err) {
console.log(err)
errorToast(t('error'))
} finally {
setIsDownloading(false)
}
}}
>
{t('place.download')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import ApplicationDetailHeader from '~components/Account/Application/Place/Detai
import { Application } from '~typings/api'
import ApplicationRightPanel from '~components/Account/Application/Place/DetailDrawer/ApplicationRightPanel'

import { useState } from 'react'
import { useEffect, useState } from 'react'
import { Document, Page } from 'react-pdf'

import useToast from '~hooks/useToast'
import { handleApplicationDownload } from '~utils/pdf'
import ApplicationDetails from '~components/Account/Application/Place/DetailDrawer/ApplicationDetails'

const ApplicationDetailDrawer = ({
isOpen,
Expand All @@ -35,6 +36,7 @@ const ApplicationDetailDrawer = ({
}) => {
const { t } = useTranslation('application')
const { id } = application ?? {}
const [displayPdf, setDisplayPdf] = useState(false)
const [isDownloading, setIsDownloading] = useState(false)
const [scales, setScales] = useState([])
const { errorToast } = useToast()
Expand All @@ -55,27 +57,38 @@ const ApplicationDetailDrawer = ({
}
}

useEffect(() => {
setTimeout(() => {
setDisplayPdf(true)
}, 1500)
}, [id, isOpen])

if (!application) {
return null
}

return (
<Drawer isOpen={isOpen} placement="right" onClose={onClose} size="xl">
<Drawer
isOpen={isOpen}
placement="right"
onClose={() => {
setDisplayPdf(false)
onClose()
}}
size="xl"
>
<DrawerOverlay />
<DrawerContent p={6} height="100%" overflowY="auto">
<DrawerCloseButton />
<DrawerHeader paddingY={0} paddingLeft={0}>
{t('place.detail.title', { id })}
</DrawerHeader>

<VStack paddingY={4} height="100%">
<ApplicationDetailHeader application={application} />
<Divider />

<Box width="100%" height="100%" paddingBottom={'100px'}>
<Grid
templateColumns={'repeat(3, 1fr)'}
gap={4}
width="100%"
height="100%"
>
Expand All @@ -86,47 +99,52 @@ const ApplicationDetailDrawer = ({
display="flex"
height="100%"
width="100%"
flexDirection="column"
>
<Document
file={`/api/pdfs/single/${application.id}`}
onLoadSuccess={({ numPages }) => {
setNumPages(numPages)
}}
loading={
<Skeleton
height="100vh"
width="100vw"
variant="rectangle"
/>
}
style={{ height: '100%' }}
>
{Array.from(new Array(numPages), (el, index) => (
<Page
key={`page_${index + 1}`}
pageNumber={index + 1}
onRenderSuccess={(page) => {
const viewport = page.getViewport({ scale: 1 })
if (viewport) {
const orientation =
viewport.width > viewport.height
? 'landscape'
: 'portrait'
// Adjust the scale based on the orientation
const scale = orientation === 'landscape' ? 0.7 : 1.0
setScales((prevScales) => {
const newScales = [...prevScales]
newScales[index] = scale
return newScales
})
}
}}
scale={scales[index] || 1.0}
/>
))}
</Document>
<ApplicationDetails application={application} />
<Divider opacity={0.4} />
{displayPdf && (
<Document
file={application?.creation_file?.[0]?.url}
onLoadSuccess={({ numPages }) => {
setNumPages(numPages)
}}
loading={
<Skeleton
height="100vh"
width="100vw"
variant="rectangle"
/>
}
style={{ height: '100%' }}
>
{Array.from(new Array(numPages), (_el, index) => (
<Page
key={`page_${index + 1}`}
pageNumber={index + 1}
onRenderSuccess={(page) => {
const viewport = page.getViewport({ scale: 1 })
if (viewport) {
const orientation =
viewport.width > viewport.height
? 'landscape'
: 'portrait'
// Adjust the scale based on the orientation
const scale =
orientation === 'landscape' ? 0.7 : 1.0
setScales((prevScales) => {
const newScales = [...prevScales]
newScales[index] = scale
return newScales
})
}
}}
scale={scales[index] || 1.0}
/>
))}
</Document>
)}
</GridItem>

<GridItem
colSpan={{ base: 3, md: 1 }}
borderLeft={{ base: 'none', md: '1px solid lightgray' }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// @ts-nocheck
import { Box, Divider, Text, VStack } from '@chakra-ui/react'
import { useTranslation } from 'next-i18next'
import { Reference } from '~@types/reference'
import ApplicationSection from '~components/Account/Application/Place/DetailDrawer/ApplicationSection'
import ApplicationFormTitle from '~components/Campaign/Places/Application/ApplicationFormTitle'
import { Application } from '~typings/api'

const ApplicationDetails = ({ application }: { application: Application }) => {
const { t } = useTranslation('place')

return (
<VStack py={4}>
<Box width="100%">
<ApplicationFormTitle
title={t('campaignApplication.references.title')}
position="1."
/>
<VStack
px={4}
mt={4}
mb={10}
width="100%"
alignItems="flex-start"
divider={<Divider opacity={0.4} />}
>
{application?.references?.map((reference: Reference, index) => (
<Box key={index}>
<Text color="blue.500" fontWeight="semibold">
{t('campaignApplication.references.references_creation', {
index: index + 1,
})}
</Text>
<Text>{`${reference?.title}, ${reference?.year}`}</Text>
<Text>
{t('campaignApplication.references.references_actors_display', {
number: reference?.actors,
})}
<Text color="#666666">
{(Boolean(reference?.other)
? [reference?.partners, reference?.other]
: reference?.partners
)?.join(', ')}
</Text>
</Text>
</Box>
))}
</VStack>
</Box>
<Box width="100%">
<ApplicationFormTitle
title={t('campaignApplication.general.title')}
position="2."
/>
<VStack py={4} divider={<Divider opacity={0.4} />} spacing={4} mb={10}>
<ApplicationSection
label={t('campaignApplication.general.subtitle', {
place:
application?.disponibility?.espace?.users_permissions_user
?.structureName,
})}
>
{Boolean(application?.already_supported) ? 'Oui' : 'Non'}
</ApplicationSection>
<ApplicationSection label={t('campaignApplication.general.bio')}>
{application?.cv}
</ApplicationSection>
</VStack>
</Box>
<Box width="100%">
<ApplicationFormTitle
title={t('campaignApplication.creation.title')}
position="3."
/>
<VStack py={4} divider={<Divider opacity={0.4} />} spacing={4} mb={10}>
<ApplicationSection
label={t('campaignApplication.creation.field_title')}
>
{application?.creation_title}
</ApplicationSection>
<ApplicationSection label={t('campaignApplication.creation.dancers')}>
{application?.creation_dancers}
</ApplicationSection>
<ApplicationSection label={t('campaignApplication.creation.summary')}>
{application?.creation_summary}
</ApplicationSection>
<ApplicationSection
label={t('campaignApplication.creation.partnerships')}
>
{application?.creation_partnerships}
</ApplicationSection>
<ApplicationSection
label={t('campaignApplication.creation.technical')}
>
{application?.creation_techical_requirements}
</ApplicationSection>
<ApplicationSection
label={t('campaignApplication.creation.accomodation')}
>
{Boolean(application?.creation_accomodation)
? t('campaignApplication.creation.yes')
: t('campaignApplication.creation.no')}
</ApplicationSection>
</VStack>
</Box>
</VStack>
)
}

export default ApplicationDetails
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Text, VStack } from '@chakra-ui/react'
import { ReactNode } from 'react-markdown'

const ApplicationSection = ({
label,
children,
}: {
label: ReactNode
children: ReactNode
}) => (
<VStack width="100%" alignItems="flex-start" spacing={1}>
<Text fontWeight="semibold">{label}</Text>
<Text> {children}</Text>
</VStack>
)

export default ApplicationSection
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@mapbox/mapbox-sdk": "^0.12.1",
"@react-pdf/renderer": "1.6.17",
"@svgr/webpack": "^6.2.1",
"adm-zip": "^0.5.10",
"axios": "^0.21.1",
"babel-plugin-transform-require-ignore": "^0.1.1",
"date-fns": "^2.19.0",
Expand Down
Loading

0 comments on commit 041cbd1

Please sign in to comment.