Skip to content

Commit

Permalink
[EN-4026] chore(navigation): pass components using forms in typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
emile-bex committed Aug 23, 2023
1 parent 75117e9 commit 69662df
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 99 deletions.
14 changes: 8 additions & 6 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
BusinessLineValue,
ExternalOfferOrigin,
HeardAboutValue,
CandidateHelpWithValue,
CompanyApproach,
} from 'src/constants';
import { AdminZone, Department } from 'src/constants/departements';
import { AdminRole, Gender, UserRole } from 'src/constants/users';
Expand Down Expand Up @@ -388,13 +390,13 @@ export type ContactContactUs = {
export type ContactCompany = {
firstName: string;
lastName: string;
approach: object;
approach: CompanyApproach;
email: string;
company: string;
position: string;
zone: object;
zone: AdminZone;
phone?: string;
heardAbout?: object;
heardAbout?: HeardAboutValue;
};

export type ContactCandidate = {
Expand All @@ -406,9 +408,9 @@ export type ContactCandidate = {
workerPhone: string;
firstName: string;
lastName: string;
helpWith: string[];
helpWith: CandidateHelpWithValue[];
gender: Gender;
birthDate?: Date;
birthDate?: string;
address?: string;
postalCode: string;
city: string;
Expand All @@ -424,7 +426,7 @@ export type ContactCandidate = {
socialSecurity: string;
handicapped?: string;
bankAccount: string;
businessLines?: string[];
businessLines?: BusinessLineValue[];
description: string;
heardAbout: string;
diagnostic?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import PropTypes from 'prop-types';
import React from 'react';
import { formEditPassions } from 'src/components/forms/schemas/formEditPassions';
import { openModal } from 'src/components/modals/Modal';
import { ModalEdit } from 'src/components/modals/Modal/ModalGeneric/ModalEdit';
import { Grid, ButtonIcon, Icon } from 'src/components/utils';

export const PassionsCard = ({ list, onChange }) => {
interface Passion {
name: string;
order: number;
}

interface PassionProps {
list: Passion[];
onChange: (updatedPassions: { passions: Passion[] }) => void;
}
export const PassionsCard = ({ list, onChange }: PassionProps) => {
return (
<div className="uk-card uk-card-default uk-card-body">
<Grid gap="small" between eachWidths={['expand', 'auto']}>
Expand All @@ -23,7 +31,6 @@ export const PassionsCard = ({ list, onChange }) => {
onClick={() => {
openModal(
<ModalEdit
id="modal-passions"
title="Édition - Mes passions (6 maximum)"
formSchema={formEditPassions}
defaultValues={list.reduce((acc, { name }, i) => {
Expand All @@ -37,9 +44,10 @@ export const PassionsCard = ({ list, onChange }) => {
.filter((val) => {
return !!val;
})
.map((val) => {
.map((val, index) => {
return {
name: val,
order: index,
};
}),
};
Expand All @@ -55,7 +63,7 @@ export const PassionsCard = ({ list, onChange }) => {
{list.length !== 0 ? (
list.map(({ name }, i) => {
return (
<li id={i} key={i}>
<li id={i.toString()} key={i}>
{name}
</li>
);
Expand All @@ -67,15 +75,3 @@ export const PassionsCard = ({ list, onChange }) => {
</div>
);
};
PassionsCard.propTypes = {
list: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
})
),
onChange: PropTypes.func,
};
PassionsCard.defaultProps = {
list: [],
onChange: null,
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import PropTypes from 'prop-types';
import React from 'react';
import { formEditSkills } from 'src/components/forms/schemas/formEditSkills';
import { openModal } from 'src/components/modals/Modal';
import { ModalEdit } from 'src/components/modals/Modal/ModalGeneric/ModalEdit';
import { Grid, ButtonIcon, Icon } from 'src/components/utils';

export const SkillsCard = ({ list, onChange }) => {
interface Skill {
name: string;
order: number;
}
interface SkillsCardProps {
list: Skill[];
onChange: (updatedSkills: { skills: Skill[] }) => void;
}
export const SkillsCard = ({ list = [], onChange }: SkillsCardProps) => {
return (
<div className="uk-card uk-card-secondary uk-card-body">
<Grid gap="small" between eachWidths={['expand', 'auto']}>
Expand Down Expand Up @@ -36,9 +43,10 @@ export const SkillsCard = ({ list, onChange }) => {
.filter((val) => {
return !!val;
})
.map((val) => {
.map((val, index) => {
return {
name: val,
order: index,
};
}),
};
Expand All @@ -54,7 +62,7 @@ export const SkillsCard = ({ list, onChange }) => {
{list.length !== 0 ? (
list.map(({ name }, i) => {
return (
<li id={i} key={i}>
<li id={i.toString()} key={i}>
{name}
</li>
);
Expand All @@ -66,16 +74,3 @@ export const SkillsCard = ({ list, onChange }) => {
</div>
);
};
SkillsCard.propTypes = {
list: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
})
),
onChange: PropTypes.func,
};

SkillsCard.defaultProps = {
list: [],
onChange: null,
};
31 changes: 0 additions & 31 deletions src/components/cv/CVEditCareerPath.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import React from 'react';
import { DefaultValues } from 'react-hook-form';
import { ExtractFormSchemaValidation } from '../forms/FormSchema';
Expand Down Expand Up @@ -145,33 +144,3 @@ export const CVEditCareerPath = ({
</div>
);
};

CVEditCareerPath.propTypes = {
ambitions: PropTypes.oneOfType([
PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
order: PropTypes.number.isRequired,
prefix: PropTypes.oneOf(
AMBITIONS_PREFIXES.map(({ value }) => {
return value;
})
),
})
),
PropTypes.string,
]).isRequired,
businessLines: PropTypes.oneOfType([
PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
order: PropTypes.number.isRequired,
})
),
PropTypes.string,
]).isRequired,
onChange: PropTypes.func,
};
CVEditCareerPath.defaultProps = {
onChange: null,
};
2 changes: 1 addition & 1 deletion src/components/forms/schemas/formCandidateContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const formCandidateContact: FormSchema<{
socialSecurity: CandidateYesNoValue;
handicapped: CandidateYesNoValue;
bankAccount: CandidateYesNoValue;
businessLines: FilterConstant<BusinessLineValue>;
businessLines: FilterConstant<BusinessLineValue>[];
description: string;
heardAbout: HeardAboutValue;
diagnostic: string;
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/schemas/formResetPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormSchema } from '../FormSchema';

export const formResetPassword: FormSchema<{
newPassword: string;
confirmPassword: boolean;
confirmPassword: string;
}> = {
id: 'form-reset-pwd',
fields: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ModalEdit } from 'src/components/modals/Modal/ModalGeneric/ModalEdit';
import { FB_TAGS, GA_TAGS } from 'src/constants/tags';
import { fbEvent } from 'src/lib/fb';
import { gaEvent } from 'src/lib/gtag';
import { getValueFromFormField } from 'src/utils';

export const CandidateContactModal = () => {
return (
Expand Down Expand Up @@ -54,8 +53,8 @@ export const CandidateContactModal = () => {
try {
await Api.postContactCandidate({
...fields,
helpWith: getValueFromFormField(helpWith),
businessLines: getValueFromFormField(businessLines),
helpWith: helpWith.map(({ value }) => value),
businessLines: businessLines.map(({ value }) => value),
});
gaEvent(GA_TAGS.PAGE_ORIENTER_ENVOYER_INSCRIPTION_CLIC);
fbEvent(FB_TAGS.SOCIAL_WORKER_REGISTRATION_SEND);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import PropTypes from 'prop-types';
import React from 'react';
import UIkit from 'uikit';

Expand All @@ -12,7 +11,10 @@ import { GA_TAGS } from 'src/constants/tags';
import { useNewsletterTracking } from 'src/hooks';
import { gaEvent } from 'src/lib/gtag';

export const ModalShareCV = ({ firstName }) => {
interface ModalShareCVProps {
firstName: string;
}
export const ModalShareCV = ({ firstName }: ModalShareCVProps) => {
const newsletterParams = useNewsletterTracking();

return (
Expand Down Expand Up @@ -99,11 +101,3 @@ export const ModalShareCV = ({ firstName }) => {
/>
);
};

ModalShareCV.propTypes = {
firstName: PropTypes.string,
};

ModalShareCV.defaultProps = {
firstName: undefined,
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useRouter } from 'next/router';
import PropTypes from 'prop-types';
import React from 'react';
import { Api } from 'src/api';
import { Layout } from 'src/components/Layout';
Expand All @@ -8,7 +7,18 @@ import { FormWithValidation } from 'src/components/forms/FormWithValidation';
import { formResetPassword } from 'src/components/forms/schemas/formResetPassword';
import { Button, Section, Icon } from 'src/components/utils';

const ResetPasswordPage = ({ valid, id, token, isCreation }) => {
interface ResetPasswordPageProps {
valid: boolean;
id: string;
token: string;
isCreation: boolean;
}
const ResetPasswordPage = ({
valid,
id,
token,
isCreation = false,
}: ResetPasswordPageProps) => {
const { push } = useRouter();

return (
Expand Down Expand Up @@ -90,15 +100,4 @@ ResetPasswordPage.getInitialProps = async ({ query }) => {
};
};

ResetPasswordPage.propTypes = {
valid: PropTypes.bool.isRequired,
id: PropTypes.string.isRequired,
token: PropTypes.string.isRequired,
isCreation: PropTypes.string,
};

ResetPasswordPage.defaultProps = {
isCreation: false,
};

export default ResetPasswordPage;
File renamed without changes.

0 comments on commit 69662df

Please sign in to comment.