Skip to content

Commit

Permalink
Testimonials fixes (reactplay#1195)
Browse files Browse the repository at this point in the history
* fixing

* lint

* fixing
  • Loading branch information
yung-coder committed Jul 3, 2023
1 parent 4745c1f commit 4bb5f81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/common/Testimonial/TestimonialCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const TestimonialCard = ({ home, quote, name, avatarUrl, category, created_at, e
return result;
};

function replaceWithBr() {
return quote.replace(/nn+/g, '<br />');
}

return (
<div className="py-4">
<div className="flex items-center gap-4 px-6 sm:h-16">
Expand Down Expand Up @@ -48,7 +52,10 @@ const TestimonialCard = ({ home, quote, name, avatarUrl, category, created_at, e

<div className="mx-2 mt-4">
<blockquote className={`${home && 'h-32'} max-h-32 px-6 overflow-y-auto`}>
<p className="leading-relaxed text-gray-700">{quote}</p>
<p
className="leading-relaxed text-gray-700"
dangerouslySetInnerHTML={{ __html: replaceWithBr() }}
/>
</blockquote>
</div>
</div>
Expand Down
21 changes: 20 additions & 1 deletion src/common/Testimonial/TestimonialModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,40 @@ export default function TestimonialModal({ isOpen, setIsOpen }) {
fetchCategories();
}, []);

function escapeNewLinesAndQuotes(inputString) {
const regex = /[\n\r"']/g;
const escapeMap = {
'\n': '\\n',
'\r': '\\r',
'"': '""',
"'": "'"
};

return inputString.replace(regex, (match) => escapeMap[match]);
}

const updateData = (e) => {
const fieldName = e.target.name;
let value = e.target.value;
let regex = /<("[^"]*"|'[^']*'|[^'">])*>/;
if (value.match(regex)) {
value = DOMPurify.sanitize(value);
}

value = escapeNewLinesAndQuotes(value);

setTestimonialData((prev) => ({
...prev,
[fieldName]: value
}));
};

useEffect(() => {
if (testimonialData.quote.length != 0 && testimonialData.event != 0) {
if (
testimonialData.quote.length != 0 &&
testimonialData.event != 0 &&
testimonialData.quote.length <= 1024
) {
setBtnDisabled(false);
} else {
setBtnDisabled(true);
Expand Down

0 comments on commit 4bb5f81

Please sign in to comment.