Skip to content

Commit

Permalink
Merge pull request #131 from AtelierdeParis/feature/folder-and-bug-fix
Browse files Browse the repository at this point in the history
feat: folder improvement and bug fix
  • Loading branch information
baptadn authored Mar 18, 2024
2 parents f3fa410 + 6dce81e commit 74d7fcb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 31 deletions.
7 changes: 4 additions & 3 deletions back/api/application/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ module.exports = {
const query =
type === 'place'
? {
...initialQuery,
'disponibility.espace.users_permissions_user.id': id,
}
...initialQuery,
'disponibility.espace.users_permissions_user.id': id,
}
: { ...initialQuery, company: id }
const populate =
type === 'place'
Expand Down Expand Up @@ -59,6 +59,7 @@ module.exports = {
'creation_file',
'campaign',
'company',
'espace',
],
)

Expand Down
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/10/2024 10:56:56 PM"
"x-generation-date": "03/18/2024 6:34:37 PM"
},
"x-strapi-config": {
"path": "/documentation",
Expand Down
4 changes: 3 additions & 1 deletion web/components/Account/AccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ const AccountMenu = ({ user }: { user: UsersPermissionsUser }) => {
currentCampaign.mode !== 'closed')

const hideApplication =
currentCampaign?.mode === 'preselections' &&
['waiting_preselections', 'preselections'].includes(
currentCampaign?.mode,
) &&
!applications?.length &&
user?.type === 'company'

Expand Down
6 changes: 6 additions & 0 deletions web/components/Campaign/CampaignProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const CampaignProvider = ({ children }: ICampaignProvider) => {
today <= getEndDateTime(campaign.application_end)
) {
return 'applications'
} else if (
today > getEndDateTime(campaign.application_end) &&
today < getStartDateTime(campaign.preselection_start)
) {
return 'waiting_preselections'
} else if (
today >= getStartDateTime(campaign.preselection_start) &&
today <= getEndDateTime(campaign.preselection_end)
Expand All @@ -64,6 +69,7 @@ const CampaignProvider = ({ children }: ICampaignProvider) => {
} else if (today >= getEndDateTime(campaign.preselection_end)) {
return 'closed'
}

return null
}

Expand Down
20 changes: 11 additions & 9 deletions web/components/Campaign/Home/ApplicationsCampaignInsert.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { VStack, Text, Box, Button, HStack, Stack } from '@chakra-ui/react'
import Hands from 'public/assets/img/hands-outline.svg'
import theme from '~theme'
import { Box, Button, HStack, Stack, Text, VStack } from '@chakra-ui/react'
import { motion } from 'framer-motion'
import { useTranslation } from 'next-i18next'
import { ROUTE_PLACES } from '~constants'
import Tag from '~components/Tag'
import Link from '~components/Link'
import Hands from 'public/assets/img/hands-outline.svg'
import ApplicationCounter from '~components/Campaign/ApplicationCounter'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import Link from '~components/Link'
import Tag from '~components/Tag'
import { ROUTE_PLACES } from '~constants'
import theme from '~theme'
import { format } from '~utils/date'
import ApplicationCounter from '~components/Campaign/ApplicationCounter'
import { motion } from 'framer-motion'

const ApplicationsCampaignInsert = () => {
const { currentCampaign } = useCampaignContext()
Expand All @@ -28,7 +28,9 @@ const ApplicationsCampaignInsert = () => {
transition="3s linear"
>
<Box>
<Tag status="campaign">{t(`campaign.title`,{title: currentCampaign?.title})}</Tag>
<Tag status="campaign">
{t(`campaign.title`, { title: currentCampaign?.title })}
</Tag>
</Box>

<Box width="100%">
Expand Down
24 changes: 12 additions & 12 deletions web/components/Place/PlacesCampaignTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import React, { useEffect, useState } from 'react'
import {
Tabs,
TabPanels,
TabPanel,
TabList,
Tab,
Box,
HStack,
Tab,
TabList,
TabPanel,
TabPanels,
Tabs,
Text,
Box,
} from '@chakra-ui/react'
import { format } from '~utils/date'
import Tag from '~components/Tag'
import { useTranslation } from 'next-i18next'
import PlacesPage from '~components/Place/PlacesPage'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import useCampaignContext from '~components/Campaign/useCampaignContext'
import PlacesPage from '~components/Place/PlacesPage'
import Tag from '~components/Tag'
import { format } from '~utils/date'

const PlacesCampaignTabs = () => {
const router = useRouter()
Expand Down Expand Up @@ -87,7 +87,7 @@ const PlacesCampaignTabs = () => {
paddingY={2}
borderRadius="12px"
>
{t(`campaign.title`,{title: currentCampaign?.title})}
{t(`campaign.title`, { title: currentCampaign?.title })}
</Text>

<Tag status="campaign" display={{ base: 'none', md: 'block' }}>
Expand Down
16 changes: 12 additions & 4 deletions web/pages/api/pdfs/selected/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AdmZip from 'adm-zip'
import { getSession } from 'next-auth/client'
import { client } from '~api/client-api'
import ApplicationDocument from '~components/pdfs/ApplicationDocument'
import { format } from '~utils/date'
import { formatCampaignZipName, getBufferFromStream } from '~utils/pdf'

const SelectedCampaignApplications = async (req, res) => {
Expand All @@ -18,7 +19,6 @@ const SelectedCampaignApplications = async (req, res) => {

const zip = new AdmZip()
const { data: campaign } = await client.campaigns.campaignsDetail(campaignId)
console.log({jwt:session.user.jwt})

try {
const {
Expand All @@ -32,7 +32,6 @@ const SelectedCampaignApplications = async (req, res) => {
},
)


// Group by place
const groupedApplications = selectedApplications.reduce(
(grouped, application) => {
Expand Down Expand Up @@ -64,6 +63,7 @@ const SelectedCampaignApplications = async (req, res) => {

for (const userId of userIds) {
const applications = groupedApplications[userId]

const place =
applications[0]?.disponibility?.espace?.users_permissions_user
const name = place?.structureName
Expand All @@ -76,9 +76,17 @@ const SelectedCampaignApplications = async (req, res) => {
)

const refLabel = `Ref. ${application.id}`

const disponibilityLabel = `${format(
application.disponibility?.start,
'dd-MM',
)} au ${format(application.disponibility?.end, 'dd-MM')}`

const subFolder = `${application?.espace?.name} - ${disponibilityLabel} - ${refLabel} - ${structureName}`

const streamBuffer = await getBufferFromStream(stream)
await zip.addFile(
`${name}/${refLabel} - ${structureName}/${refLabel} - Candidature.pdf`,
`${name}/${subFolder}/${refLabel} - Candidature.pdf`,
streamBuffer,
)

Expand All @@ -88,7 +96,7 @@ const SelectedCampaignApplications = async (req, res) => {
const creationFileArrayBuffer = await creationFile.buffer()

await zip.addFile(
`${name}/${refLabel} - ${structureName}/${refLabel} - Dossier artistique.pdf`,
`${name}/${subFolder}/${refLabel} - Dossier artistique.pdf`,
creationFileArrayBuffer,
)
}
Expand Down
7 changes: 6 additions & 1 deletion web/pages/compte/mes-candidatures/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ const CompanyApplications = ({ user }: Props) => {
return null
}

if (currentCampaign?.mode === 'preselections' && applications?.length === 0) {
if (
['preselections', 'waiting_preselections'].includes(
currentCampaign?.mode,
) &&
applications?.length === 0
) {
router.push(ROUTE_ACCOUNT)
return null
}
Expand Down

0 comments on commit 74d7fcb

Please sign in to comment.