Skip to content

Commit

Permalink
[EN-6289] feat(cv): preview and max lines
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulEntourage committed Sep 6, 2023
1 parent 6fccf24 commit 4105cf2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const CVFicheEdition = ({
updateImage();
}
}, [prevPreviewGenerating, previewGenerating, updateImage]);

return (
<Grid childWidths={['1-1']}>
<Grid childWidths={['1-1']} match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export const CVModalPreview = ({ imageUrl, cv }: ModalPreviewProps) => {
const [cvPreview, setCVPreview] = useState<CV>(cv);

useEffect(() => {
setCVPreview({ ...cv, urlImg: imageUrl });
const previewHash = Date.now();
const baseUrl = `${process.env.AWSS3_IMAGE_DIRECTORY}${cv.UserId}.${cv.status}`;
setCVPreview({ ...cv, urlImg: `${baseUrl}.jpg?${previewHash}` });
}, [imageUrl, cv]);

return (
Expand Down
1 change: 1 addition & 0 deletions src/components/cv/CVPDF/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CVPDF } from './CVPDF';
14 changes: 12 additions & 2 deletions src/components/forms/fields/GenericField.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import {
Control,
useController,
Expand Down Expand Up @@ -64,7 +64,16 @@ export function GenericField<S extends FormSchema<AnyCantFix>>({
}: GenericFieldProps<S>) {
const { id: formId } = formSchema;

const rules = mapFieldRules<S, typeof field.component>(field.rules);
let rules = mapFieldRules<S, typeof field.component>(field.rules);
const [isMaxLinesReached, setIsMaxLinesReached] = useState<boolean>();

if (field.maxLines) {
rules = {
...rules,
maxLines: () =>
!isMaxLinesReached || 'Vous avez dépassé le nombre de lignes maximum',
};
}

const {
field: { onChange, onBlur, value, name, ref },
Expand Down Expand Up @@ -156,6 +165,7 @@ export function GenericField<S extends FormSchema<AnyCantFix>>({
{...commonProps}
maxLines={field.maxLines}
maxLength={field.maxLength}
setIsMaxLinesReached={setIsMaxLinesReached}
/>
);
}
Expand Down
13 changes: 12 additions & 1 deletion src/components/utils/Inputs/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ChangeEvent } from 'react';
import React, { ChangeEvent, useEffect } from 'react';
import {
StyledAnnotations,
StyledAnnotationsErrorMessage,
Expand All @@ -19,6 +19,7 @@ interface TextAreaProps extends CommonInputProps<string, HTMLTextAreaElement> {
maxLines?: { lines: number; width: number };
maxLength?: number;
rows?: number;
setIsMaxLinesReached?: (isMaxLinesReached: boolean) => void;
}

export function TextArea({
Expand All @@ -37,6 +38,7 @@ export function TextArea({
showLabel,
inputRef,
rows,
setIsMaxLinesReached,
}: TextAreaProps) {
const isMobile = useIsMobile();

Expand All @@ -47,6 +49,15 @@ export function TextArea({
maxLines?.lines
);

useEffect(() => {
if (!maxLines) return null;
if (remainingLines <= 0) {
setIsMaxLinesReached(true);
} else {
setIsMaxLinesReached(false);
}
});

if (hidden) {
return null;
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/utils/Inputs/TextArea/useLineLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function useLineLimit(
const nbOfLines = Math.ceil(
(taHeight - taPaddingBottom - taPaddingTop) / taLineHeight
);
setNumberOfLines(!value ? 0 : nbOfLines);

if (nbOfLines > maxLines) {
if (!prevValue || value.length - prevValue.length > 1) {
Expand All @@ -79,11 +80,12 @@ export function useLineLimit(
'danger'
);
}

onChange(prevValue);
} else {
setNumberOfLines(!value ? 0 : nbOfLines);
// onChange(prevValue);
}
// else {
// // console.log(value);
// setNumberOfLines(!value ? 0 : nbOfLines);
// }
}
}, [calculateContentHeight, maxLines, name, onChange, prevValue, ref, value]);

Expand Down

0 comments on commit 4105cf2

Please sign in to comment.