Skip to content

Commit

Permalink
UTOPIA-1583: Fix ppq richtext
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyMitch committed Nov 21, 2023
1 parent 0723b89 commit e670300
Showing 1 changed file with 7 additions and 33 deletions.
40 changes: 7 additions & 33 deletions src/frontend/src/components/public/PIAFormTabs/ppq/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,12 @@ const PPQ = ({ printPreview }: IPPQProps) => {
const [ppqForm, setPpqForm] = useState<IPPQ>(initialFormState);

// Function to handle state changes for ppqForm
const stateChangeHandler = (value: any, key: keyof IPPQ) => {
setNestedReactState(setPpqForm, key, value);
};
// Function to handle text editor state changes for ppqForm
const textEditorStateChangeHandler = (value: any, path: string) => {
const stateChangeHandler = (value: any, path: string) => {
setNestedReactState(setPpqForm, path, value);
};

// State for character count
const [pidSummaryCharCount, setpidSummaryCharCount] = useState<number>(0);
// TEMPORARY: State for character count
const pidSummaryCharCount = 0;

// State for rich text editors.
const [initiativeOtherDetails, setInitiativeOtherDetails] = useState(
Expand All @@ -88,51 +84,29 @@ const PPQ = ({ printPreview }: IPPQProps) => {

// Update form state on rich text editor changes.
useEffect(() => {
textEditorStateChangeHandler(
stateChangeHandler(
initiativeOtherDetails,
'initiativeOtherDetails.content',
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initiativeOtherDetails]);

useEffect(() => {
textEditorStateChangeHandler(
stateChangeHandler(
proposedDeadlineReason,
'proposedDeadlineReason.content',
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [proposedDeadlineReason]);

useEffect(() => {
// Get the pidcurrent length of the pidInitiativeSummary state.
const currentLength = pidInitiativeSummary.length;

// If the current length is greater than 500.
if (currentLength > 500) {
// Truncate the string to 500 characters.
const truncatedSummary = pidInitiativeSummary.slice(0, 500);
// Set the truncated string as the new state.
setPidInitiativeSummary(truncatedSummary);
// Set the character count to 500.
setpidSummaryCharCount(500);
} else {
// If the current length is 500 or less, set the character count to the current length.
setpidSummaryCharCount(currentLength);
}

// Call the stateChangeHandler to update the pidInitiativeSummary state.
textEditorStateChangeHandler(
pidInitiativeSummary,
'pidInitiativeSummary.content',
);
stateChangeHandler(pidInitiativeSummary, 'pidInitiativeSummary.content');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pidInitiativeSummary]);

useEffect(() => {
textEditorStateChangeHandler(
otherCpoConsideration,
'otherCpoConsideration.content',
);
stateChangeHandler(otherCpoConsideration, 'otherCpoConsideration.content');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [otherCpoConsideration]);

Expand Down

0 comments on commit e670300

Please sign in to comment.