Skip to content

Commit

Permalink
[APP-1004][APP-1005][APP-1006] Fix generator UI and logic, fix statem…
Browse files Browse the repository at this point in the history
…ent UI, fix copy link (#144)

* [APP-1004] Fix generator UI and logic

* [APP-1005] Fix statement UI

* [APP-1005] Fix statement UI

* Mixpanel record session
  • Loading branch information
DinetsV authored Jan 21, 2025
1 parent f95dab6 commit 034d684
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 51 deletions.
6 changes: 3 additions & 3 deletions modules/settings/assets/js/components/copy-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ const CopyLink = ({ content }) => {
title={
copied
? __('Copied!', 'pojo-accessibility')
: __('Copy', 'pojo-accessibility')
: __('Copy link', 'pojo-accessibility')
}
arrow={true}
PopperProps={{
modifiers: [
{
name: 'offset',
options: {
offset: [0, -8], // Adjusts the vertical (top) margin
offset: [0, -16], // Adjusts the vertical (top) margin
},
},
{
Expand All @@ -56,7 +56,7 @@ const CopyLink = ({ content }) => {
>
<IconButton
onClick={copyToClipboard}
sx={{ width: '50px', height: '50px', marginLeft: 2 }}
sx={{ width: '50px', height: '50px', marginLeft: 1 }}
>
<LinkIcon width="1em" height="1em" />
</IconButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ const HtmlToTypography = ({ htmlString, replacements }) => {
'p',
'span',
'div',
'strong',
];
if (supportedTags.includes(tagName)) {
return (
<Typography
variant={tagName === 'p' ? 'body2' : 'subtitle2'}
component={tagName}
marginBottom={1}
sx={node.attribs.class ? { textAlign: 'center' } : {}} //for correct render on preview
>
{node.children && node.children.map((child) => transform(child))}
</Typography>
Expand Down
73 changes: 37 additions & 36 deletions modules/settings/assets/js/components/statement-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { styled } from '@elementor/ui/styles';
import { AlertError, HtmlToTypography } from '@ea11y/components';
import { useSettings, useStorage, useToastNotification } from '@ea11y/hooks';
import { mixpanelService } from '@ea11y/services';
import { useState, useEffect } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import API from '../../api';
import { Statement } from '../../helpers/accessibility-statement';
Expand Down Expand Up @@ -45,10 +45,9 @@ const StyledTextField = styled(TextField)`
`;

const StatementGenerator = ({ open, close }) => {
const [isValidName, setValidName] = useState(null);
const [isValidEmail, setValidEmail] = useState(null);
const [isValidDomain, setValidDomain] = useState(null);
const [disableCreateButton, setDisabledCreateButton] = useState(true);
const [isValidName, setValidName] = useState(true);
const [isValidEmail, setValidEmail] = useState(true);
const [isValidDomain, setValidDomain] = useState(true);
const { success, error } = useToastNotification();

const {
Expand All @@ -59,43 +58,41 @@ const StatementGenerator = ({ open, close }) => {
} = useSettings();
const { save } = useStorage();

useEffect(() => {
if (checkEmail(companyData?.company_email)) {
setValidEmail(true);
} else {
setValidEmail(false);
}

if (checkCompanyName(companyData?.company_name)) {
setValidName(true);
} else {
setValidName(false);
}

if (checkDomain(companyData?.company_website)) {
setValidDomain(true);
} else {
setValidDomain(false);
}
}, [companyData]);

useEffect(() => {
if (!isValidEmail || !isValidName || !isValidDomain) {
setDisabledCreateButton(true);
} else {
setDisabledCreateButton(false);
}
}, [isValidName, isValidEmail, isValidDomain]);
const isSubmitEnabled =
companyData.company_name &&
companyData.company_website &&
companyData.company_email &&
isValidEmail &&
isValidName &&
isValidDomain;

const handleClose = () => {
close();
};

const validateForm = (key, value) => {
switch (key) {
case 'company_website':
setValidDomain(checkDomain(value));
break;
case 'company_name':
setValidName(checkCompanyName(value));
break;
case 'company_email':
setValidEmail(checkEmail(value));
break;
default:
break;
}
};

const updateCompanyData = (key, value) => {
setCompanyData((prevData) => ({
...prevData,
const data = {
...companyData,
[key]: value,
}));
};
setCompanyData(data);
validateForm(key, value);
};

const createPage = async () => {
Expand Down Expand Up @@ -145,6 +142,7 @@ const StatementGenerator = ({ open, close }) => {
aria-describedby="alert-dialog-description"
fullWidth
maxWidth="lg"
sx={{ zIndex: 99999 }}
>
<DialogHeader onClose={handleClose}>
<DialogTitle>
Expand Down Expand Up @@ -178,6 +176,7 @@ const StatementGenerator = ({ open, close }) => {
color="secondary"
margin="normal"
value={companyData.company_name}
placeholder="Acme Inc."
onChange={(e) =>
updateCompanyData('company_name', e.currentTarget.value)
}
Expand All @@ -200,6 +199,7 @@ const StatementGenerator = ({ open, close }) => {
color="secondary"
margin="normal"
value={companyData.company_website}
placeholder="https://www.acme.com/"
onChange={(e) =>
updateCompanyData('company_website', e.currentTarget.value)
}
Expand All @@ -222,6 +222,7 @@ const StatementGenerator = ({ open, close }) => {
color="secondary"
margin="normal"
value={companyData.company_email}
placeholder="[email protected]"
onChange={(e) =>
updateCompanyData('company_email', e.currentTarget.value)
}
Expand Down Expand Up @@ -268,7 +269,7 @@ const StatementGenerator = ({ open, close }) => {
onClick={createPage}
variant="contained"
color="info"
disabled={disableCreateButton}
disabled={!isSubmitEnabled}
>
{__('Create statement & page', 'pojo-accessibility')}
</Button>
Expand Down
12 changes: 6 additions & 6 deletions modules/settings/assets/js/helpers/accessibility-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { __, sprintf } from '@wordpress/i18n';

/* eslint-disable @wordpress/i18n-translator-comments */
export const Statement = `
<!-- wp:heading {"level":6} -->
<h6>${sprintf(__('Accessibility Statement for %s', 'pojo-accessibility'), '{company_website}')}</h6>
<!-- wp:heading {"textAlign":"center","level":6} -->
<h6 class="wp-block-heading has-text-align-center">${sprintf(__('Accessibility Statement for %s', 'pojo-accessibility'), '{company_website}')}</h6>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>${sprintf(__('%s is committed to ensuring digital accessibility for people with disabilities. We are continually improving the user experience for everyone and applying the relevant accessibility standards.', 'pojo-accessibility'), '{company_name}')}</p>
<p>${sprintf(__('%s is committed to ensuring digital accessibility for people with disabilities. We are continually improving the user experience for everyone and applying the relevant accessibility standards.', 'pojo-accessibility'), '<strong>{company_name}</strong>')}</p>
<!-- /wp:paragraph -->
<!-- wp:heading {"level":6} -->
<h6>${__('Conformance status', 'pojo-accessibility')}</h6>
Expand All @@ -15,7 +15,7 @@ export const Statement = `
<p>${__('The Web Content Accessibility Guidelines (WCAG) defines requirements for designers and developers to improve accessibility for people with disabilities. It defines three levels of conformance: Level A, Level AA, and Level AAA.', 'pojo-accessibility')}</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>${sprintf(__('As of the date of this statement, %s website is partially conformant with WCAG 2.2 level AA. Partially conformant means that some parts of the content do not fully conform to the accessibility standard.', 'pojo-accessibility'), '{company_name}')}</p>
<p>${sprintf(__('As of the date of this statement, %s website is partially conformant with WCAG 2.2 level AA. Partially conformant means that some parts of the content do not fully conform to the accessibility standard.', 'pojo-accessibility'), '<strong>{company_name}</strong>')}</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>${__('We are currently working on remediating our website to ensure the best quality usability for all of our users.', 'pojo-accessibility')}</p>
Expand All @@ -24,10 +24,10 @@ export const Statement = `
<h6>${__('Feedback', 'pojo-accessibility')}</h6>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>${sprintf(__('We welcome your feedback on the accessibility of %s website. Please let us know if you encounter accessibility barriers on our website:', 'pojo-accessibility'), '{company_name}')}</p>
<p>${sprintf(__('We welcome your feedback on the accessibility of %s website. Please let us know if you encounter accessibility barriers on our website:', 'pojo-accessibility'), '<strong>{company_name}</strong>')}</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>${sprintf(__('E-mail: %s', 'pojo-accessibility'), '{company_email}')}</p>
<p>${sprintf(__('E-mail: %s', 'pojo-accessibility'), '<strong>{company_email}</strong>')}</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>${__('We try to respond to feedback within 3–5 business days.', 'pojo-accessibility')}</p>
Expand Down
6 changes: 3 additions & 3 deletions modules/settings/assets/js/hooks/use-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ export const SettingsProvider = ({ children }) => {
});

const [companyData, setCompanyData] = useState({
company_name: 'Acme Inc.',
company_website: 'https://www.acme.com/',
company_email: '[email protected]',
company_name: '',
company_website: '',
company_email: '',
current_date: new Date().toLocaleDateString(),
});

Expand Down
5 changes: 5 additions & 0 deletions modules/settings/assets/js/layouts/statement-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ const StatementLink = () => {
content={<GeneratedPageInfoTipCard />}
disableHoverListener
disableFocusListener
PopperProps={{
sx: {
zIndex: 9999999999, // Custom z-index for the popper
},
}}
open={showAccessibilityGeneratedInfotip}
>
<Select
Expand Down
16 changes: 13 additions & 3 deletions modules/settings/assets/js/pages/accessibility-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const StyledPaper = styled(Paper)`
align-items: center;
justify-content: center;
padding: 24px;
width: 500px;
min-height: 169px;
width: 376px;
min-height: 264px;
border-radius: ${({ theme }) => theme.shape.borderRadius};
box-shadow: ${({ theme }) => theme.shadows[0]};
cursor: pointer;
Expand Down Expand Up @@ -118,6 +118,8 @@ const AccessibilityStatement = () => {
href={'https://example.com/'}
target="_blank"
rel="noopener noreferrer"
color="secondary"
underline="hover"
>
{children}
</Link>
Expand All @@ -128,7 +130,13 @@ const AccessibilityStatement = () => {

{!accessibilityStatementData?.pageId && !showStatementLink && (
<>
<FormControl>
<FormControl
sx={{
display: 'flex',
justifyContent: 'center',
width: '100%',
}}
>
<FormLabel
id="icon-select-radio-buttons-group-label"
color="secondary"
Expand Down Expand Up @@ -165,9 +173,11 @@ const AccessibilityStatement = () => {
value={statementOption}
sx={{
display: 'flex',
justifyContent: 'center',
flexDirection: 'row',
flexWrap: 'nowrap',
gap: 5,
width: '100%',
}}
>
<StyledPaper
Expand Down
1 change: 1 addition & 0 deletions modules/settings/assets/js/services/mixpanel-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const init = async () => {
debug: ea11ySettingsData.pluginEnv === 'dev',
track_pageview: false,
persistence: 'localStorage',
record_sessions_percent: 50,
});

mixpanel.register({
Expand Down

0 comments on commit 034d684

Please sign in to comment.