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

MEP 26/06/2024 #797

Merged
merged 14 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/review-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

# TODO: do not create it if exists
- name: Create postgres addon
run: clever addon create postgresql-addon $PR_NAME-postgres --org $ORGA_ID --plan dev --region par
run: clever addon create postgresql-addon $PR_NAME-postgres --org $ORGA_ID --plan xxs_sml --region par

- name: Create redis addon
run: clever addon create redis-addon $PR_NAME-redis --org $ORGA_ID --plan s_mono --region par
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
clever deploy -a $APP_ALIAS

- name: Scale down for the run
run: clever scale --flavor XS -a $APP_ALIAS
run: clever scale --flavor S -a $APP_ALIAS

deploy-queue:
if: github.event.action == 'opened' || github.event.action == 'reopened'
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
clever deploy -a $APP_ALIAS

- name: Scale down for the run
run: clever scale --flavor XS -a $APP_ALIAS
run: clever scale --flavor M -a $APP_ALIAS

deploy-front:
if: github.event.action == 'opened' || github.event.action == 'reopened'
Expand Down Expand Up @@ -239,7 +239,7 @@ jobs:
run: clever deploy --force -a $APP_ALIAS

- name: Scale down for the run
run: clever scale --flavor XS -a $APP_ALIAS
run: clever scale --flavor S -a $APP_ALIAS

update-front:
if: github.event.action == 'synchronize'
Expand Down Expand Up @@ -303,7 +303,7 @@ jobs:
run: clever deploy --force -a $APP_ALIAS

- name: Scale down for the run
run: clever scale --flavor XS -a $APP_ALIAS
run: clever scale --flavor M -a $APP_ALIAS

delete-queue:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ fileignoreconfig:
checksum: 45473f39f4b07b3a33b6138a7e6fc3268690b59439d9f539eb1ce2c1abd430dc
- filename: packages/schemas/src/password.ts
checksum: 716d8d646fd8a00af8d4225e15190810f9e8ab082fbb14e7430be109fa676611
- filename: packages/utils/src/s3.ts
checksum: 3270d7c99620a1dd53f1e1a90c24ba12b2b0b090969c498fbe739776f832029a
- filename: queue/.env.example
checksum: df71affe33700cb0a36ee0b4824ef60e7d8e5a08f3d4d16ca53c31e9085b45ae
- filename: queue/README.md
Expand All @@ -80,6 +82,8 @@ fileignoreconfig:
checksum: b20a3159d29f2a0964c58d2befc040ef4f553ece130067316e651730c6c97d5b
- filename: server/src/controllers/fileController.ts
checksum: 72d31c3e49e4dbee18222e61e0a5bb48da755cefa2a8d7fa2d9f1a153290279e
- filename: server/src/controllers/fileRepository.ts
checksum: 4387143e5ef9cfb0a7168f63e361fcad10dfef5309e933d9b37c0ce89099d35a
- filename: server/src/controllers/housingExportController.ts
checksum: 41b6d72c503240edea923accce36af8548aa859d3494560eec003bac2c5ab4d5
- filename: server/src/index.ts
Expand Down
15 changes: 3 additions & 12 deletions frontend/src/components/Draft/SendButton.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import { Alert } from '@codegouvfr/react-dsfr/Alert';

import ConfirmationModal from '../modals/ConfirmationModal/ConfirmationModal';
import { useUpdateCampaignMutation } from '../../services/campaign.service';
import { Campaign } from '../../models/Campaign';
import { useForm } from '../../hooks/useForm';

interface Props {
className?: string;
campaign: Campaign;
form: ReturnType<typeof useForm>;
onSend(): void;
}

function SendButton(props: Readonly<Props>) {
const [updateCampaign] = useUpdateCampaignMutation();

function open(openModal: () => void): void {
props.form.validate(() => {
openModal();
});
}

function submit(): void {
props.form.validate(() => {
updateCampaign({
...props.campaign,
status: 'sending',
});
});
props.onSend();
}

return (
Expand All @@ -35,7 +26,7 @@ function SendButton(props: Readonly<Props>) {
openingButtonProps={{
children: 'Débuter l’envoi',
iconId: 'fr-icon-send-plane-fill',
priority: 'primary',
priority: 'primary'
}}
size="large"
title="Envoi de la campagne"
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/models/Draft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import {
DraftCreationPayloadDTO,
DraftDTO,
DraftPreviewPayloadDTO,
DraftUpdatePayloadDTO,
DraftUpdatePayloadDTO
} from '@zerologementvacant/models';
import { SenderPayload } from './Sender';
import { DeepNonNullable } from 'ts-essentials';

export interface Draft extends DraftDTO {}

export interface DraftCreationPayload
extends DeepNonNullable<DraftCreationPayloadDTO> {
sender: DeepNonNullable<SenderPayload>;
extends DeepNonNullable<Omit<DraftCreationPayloadDTO, 'logo' | 'sender'>>,
Pick<DraftCreationPayloadDTO, 'logo'> {
sender: DeepNonNullable<Omit<SenderPayload, 'signatoryFile'>> &
Pick<SenderPayload, 'signatoryFile'>;
}

export type DraftUpdatePayload = DeepNonNullable<DraftUpdatePayloadDTO>;
Expand Down
45 changes: 26 additions & 19 deletions frontend/src/views/Campaign/CampaignDraft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Campaign } from '../../models/Campaign';
import { Col, Container, Row } from '../../components/_dsfr';
import {
useCreateDraftMutation,
useUpdateDraftMutation,
useUpdateDraftMutation
} from '../../services/draft.service';
import UnsavedChanges from '../../components/UnsavedChanges/UnsavedChanges';
import PreviewButton from '../../components/Draft/PreviewButton';
Expand All @@ -25,14 +25,15 @@ import SendButton from '../../components/Draft/SendButton';
import SaveButton from '../../components/SaveButton/SaveButton';
import DraftMailInfo, {
Written,
writtenSchema,
writtenSchema
} from '../../components/Draft/DraftMailInfo';
import { DraftCreationPayload } from '../../models/Draft';
import DraftSenderLogo from '../../components/Draft/DraftSenderLogo';
import DraftSignature from '../../components/Draft/DraftSignature';
import CampaignRecipients from '../../components/Campaign/CampaignRecipients';
import CampaignCreatedFromGroup from '../../components/Campaign/CampaignCreatedFromGroup';
import { FileUploadDTO } from '@zerologementvacant/models';
import { useUpdateCampaignMutation } from '../../services/campaign.service';

const schema = yup
.object({
Expand All @@ -42,7 +43,7 @@ const schema = yup
body: yup
.string()
.required('Veuillez renseigner le contenu de votre courrier'),
sender: senderSchema,
sender: senderSchema
})
// Must do like that because the useForm hook has a validation bug
// where it creates an infinite render loop if passed a `written` object
Expand Down Expand Up @@ -73,10 +74,10 @@ function CampaignDraft(props: Readonly<Props>) {
signatoryFirstName: '',
signatoryLastName: '',
signatoryRole: '',
signatoryFile: '',
signatoryFile: null
},
writtenAt: '',
writtenFrom: '',
writtenFrom: ''
});

useEffect(() => {
Expand All @@ -97,10 +98,10 @@ function CampaignDraft(props: Readonly<Props>) {
signatoryFirstName: draft.sender?.signatoryFirstName ?? '',
signatoryLastName: draft.sender?.signatoryLastName ?? '',
signatoryRole: draft.sender?.signatoryRole ?? '',
signatoryFile: draft.sender?.signatoryFile ?? '',
signatoryFile: draft.sender?.signatoryFile
},
writtenAt: draft.writtenAt ?? '',
writtenFrom: draft.writtenFrom ?? '',
writtenFrom: draft.writtenFrom ?? ''
});
}
}, [draft, props.campaign.id]);
Expand All @@ -110,22 +111,22 @@ function CampaignDraft(props: Readonly<Props>) {
body: values.body,
sender: values.sender,
writtenAt: values.writtenAt,
writtenFrom: values.writtenFrom,
writtenFrom: values.writtenFrom
});

const hasChanges = form.isDirty && !fp.equals(draft, values);

const [createDraft, createDraftMutation] = useCreateDraftMutation();
function create(): void {
async function create(): Promise<void> {
if (!draft) {
createDraft({ ...values, campaign: props.campaign.id });
await createDraft({ ...values, campaign: props.campaign.id }).unwrap();
}
}

const [updateDraft, updateDraftMutation] = useUpdateDraftMutation();
function update(): void {
async function update(): Promise<void> {
if (draft) {
updateDraft({ ...values, id: draft.id });
await updateDraft({ ...values, id: draft.id }).unwrap();
}
}

Expand All @@ -134,6 +135,12 @@ function CampaignDraft(props: Readonly<Props>) {
? [update, updateDraftMutation]
: [create, createDraftMutation];

const [updateCampaign] = useUpdateCampaignMutation();
async function send(): Promise<void> {
await save();
await updateCampaign({ ...props.campaign, status: 'sending' });
}

function setBody(body: Body): void {
setValues({ ...values, ...body });
}
Expand All @@ -154,7 +161,7 @@ function CampaignDraft(props: Readonly<Props>) {
setValues({
...values,
writtenAt: written.at,
writtenFrom: written.from,
writtenFrom: written.from
});
}

Expand Down Expand Up @@ -186,13 +193,13 @@ function CampaignDraft(props: Readonly<Props>) {
disabled={!exists}
draft={draft}
/>
<SendButton campaign={props.campaign} form={form} />
<SendButton form={form} onSend={send} />
</Grid>
</Grid>
<Tabs
className={styles.tabs}
classes={{
panel: styles.panel,
panel: styles.panel
}}
tabs={[
{
Expand All @@ -208,7 +215,7 @@ function CampaignDraft(props: Readonly<Props>) {
isLoading={mutation.isLoading}
isSuccess={mutation.isSuccess}
message={{
success: 'Votre campagne a été sauvegardée avec succès',
success: 'Votre campagne a été sauvegardée avec succès'
}}
onSave={save}
/>
Expand Down Expand Up @@ -256,12 +263,12 @@ function CampaignDraft(props: Readonly<Props>) {
</Row>
</Container>
</form>
),
)
},
{
label: 'Destinataires',
content: <CampaignRecipients campaign={props.campaign} />,
},
content: <CampaignRecipients campaign={props.campaign} />
}
]}
/>
</Grid>
Expand Down
10 changes: 5 additions & 5 deletions packages/api-sdk/src/housing-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AxiosInstance } from 'axios';
import {
HousingDTO,
HousingFiltersDTO,
PaginationOptions,
Pagination
} from '@zerologementvacant/models';

export interface HousingAPI {
Expand All @@ -15,14 +15,14 @@ export function createHousingAPI(http: AxiosInstance): HousingAPI {
async find(opts?: FindOptions): Promise<HousingDTO[]> {
const response = await http.post('/housing', opts, {
headers: {
'Content-Type': 'application/json',
},
'Content-Type': 'application/json'
}
});
return response.data.entities;
},
}
};
}

interface FindOptions extends PaginationOptions {
interface FindOptions extends Partial<Pagination> {
filters?: HousingFiltersDTO;
}
3 changes: 3 additions & 0 deletions packages/draft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@types/async": "^3.2.24",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"copyfiles": "^2.4.1",
Expand All @@ -22,6 +23,8 @@
},
"dependencies": {
"@codegouvfr/react-dsfr": "^1.9.11",
"@zerologementvacant/utils": "workspace:^",
"async": "^3.2.5",
"handlebars": "^4.7.8",
"pdf-lib": "^1.17.1",
"puppeteer": "^22.9.0"
Expand Down
Loading
Loading