Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[features][Auth logo customization] #15096

Merged
merged 25 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1d5bdb5
auth logo customization in Overview settings form
ronronscelestes Nov 29, 2022
51cb73f
feat: added authLogo setting
vincentbpro Nov 29, 2022
fd87396
fix permissions and add test part 1
ronronscelestes Dec 1, 2022
a5ff1f2
extend test coverage part 2
ronronscelestes Dec 1, 2022
23488c3
update snapshots, update project settings on submit, update form redu…
ronronscelestes Dec 1, 2022
7a48a5f
add test to make sure updateProjectSettings is called
ronronscelestes Dec 2, 2022
98154ca
chore: update translations
ronronscelestes Dec 2, 2022
d204746
chrore: feedback fix Form tests
ronronscelestes Dec 5, 2022
40b3a78
chore: design and wording fixes
ronronscelestes Dec 5, 2022
6b97780
chore: breakdown ImageCardAsset format and size displayed test
ronronscelestes Dec 6, 2022
4e873bd
Merge pull request #15058 from strapi/authLogo/frontend
ronronscelestes Dec 6, 2022
bda682d
Merge branch 'main' of https://github.com/strapi/strapi into features…
ronronscelestes Dec 6, 2022
66691f5
updated track event on reset and change logos
ronronscelestes Dec 8, 2022
2b6b92b
Merge pull request #15125 from strapi/authLogo/tracker-update
ronronscelestes Dec 9, 2022
f3f6163
Merge branch 'main' of https://github.com/strapi/strapi into features…
ronronscelestes Dec 14, 2022
185c487
fix(project-settings): ensure to have previous settings before access…
nathan-pichon Dec 22, 2022
f51778c
Merge pull request #15051 from strapi/authLogo/backend
nathan-pichon Jan 11, 2023
aa04381
Merge branch 'main' of https://github.com/strapi/strapi into features…
ronronscelestes Jan 11, 2023
7ff704a
chore: fix snapshot
ronronscelestes Jan 11, 2023
c335d3d
fix: post request content type + axiosInstance headers
ronronscelestes Jan 11, 2023
4e52ca1
feedback fixes: conditional logo, refactor Stack, canSubmit, test naming
ronronscelestes Jan 12, 2023
67c35bc
disabled fetching when cannot read + change Form component name to Cu…
ronronscelestes Jan 13, 2023
e1c3fed
Merge branch 'main' of https://github.com/strapi/strapi into features…
ronronscelestes Jan 13, 2023
cffb932
chore: update snapshots
ronronscelestes Jan 13, 2023
6960c98
Merge branch 'main' of https://github.com/strapi/strapi into features…
ronronscelestes Jan 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
import React, { useMemo, useReducer, useRef } from 'react';
import React, { useCallback, useMemo, useReducer } from 'react';
import PropTypes from 'prop-types';
import { ConfigurationsContext } from '../../contexts';
import reducer, { initialState } from './reducer';

const ConfigurationsProvider = ({
children,
authLogo,
authLogo: defaultAuthLogo,
menuLogo: defaultMenuLogo,
showReleaseNotification,
showTutorials,
}) => {
const [{ menuLogo }, dispatch] = useReducer(reducer, initialState);
const [{ menuLogo, authLogo }, dispatch] = useReducer(reducer, initialState);

const updateProjectSettings = ({ menuLogo }) => {
return dispatch({
type: 'UPDATE_PROJECT_SETTINGS',
values: {
menuLogo: menuLogo || defaultMenuLogo,
},
});
};

const updateProjectSettingsRef = useRef(updateProjectSettings);
const updateProjectSettings = useCallback(
({ menuLogo, authLogo }) => {
return dispatch({
type: 'UPDATE_PROJECT_SETTINGS',
values: {
menuLogo: menuLogo || defaultMenuLogo,
authLogo: authLogo || defaultAuthLogo,
},
});
},
[defaultAuthLogo, defaultMenuLogo]
);

const configurationValue = useMemo(() => {
return {
logos: {
menu: { custom: menuLogo, default: defaultMenuLogo },
auth: { custom: null, default: authLogo },
auth: { custom: authLogo, default: defaultAuthLogo },
},
updateProjectSettings: updateProjectSettingsRef.current,
updateProjectSettings,
showReleaseNotification,
showTutorials,
};
}, [
authLogo,
menuLogo,
defaultMenuLogo,
authLogo,
defaultAuthLogo,
updateProjectSettings,
showReleaseNotification,
showTutorials,
updateProjectSettingsRef,
defaultMenuLogo,
]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import produce from 'immer';

const initialState = {
menuLogo: null,
authLogo: null,
};

const reducer = (state = initialState, action) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ describe('ConfigurationsProvider | reducer', () => {
const action = {
type: 'UPDATE_PROJECT_SETTINGS',
values: {
menuLogo: 'strapi.jpeg',
menuLogo: 'menu-strapi.jpeg',
authLogo: 'auth-strapi.jpeg',
},
};

const expected = {
menuLogo: 'strapi.jpeg',
menuLogo: 'menu-strapi.jpeg',
authLogo: 'auth-strapi.jpeg',
};

expect(reducer(state, action)).toEqual(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Logo = () => {
logos: { auth },
} = useConfigurations();

return <Img src={auth.default} aria-hidden alt="" />;
return <Img src={auth.custom} aria-hidden alt="" />;
ronronscelestes marked this conversation as resolved.
Show resolved Hide resolved
};

export default Logo;
6 changes: 4 additions & 2 deletions packages/core/admin/admin/src/core/utils/axiosInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { auth, wrapAxiosInstance } from '@strapi/helper-plugin';

const instance = axios.create({
baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
});

instance.interceptors.request.use(
async (config) => {
config.headers = {
Authorization: `Bearer ${auth.getToken()}`,
Accept: 'application/json',
'Content-Type': 'application/json',
};

return config;
Expand Down
8 changes: 6 additions & 2 deletions packages/core/admin/admin/src/pages/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ function App() {
try {
const {
data: {
data: { hasAdmin, uuid, menuLogo },
data: { hasAdmin, uuid, menuLogo, authLogo },
},
} = await axios.get(`${strapi.backendURL}/admin/init`);

updateProjectSettings({ menuLogo: prefixFileUrlWithBackendUrl(menuLogo) });
updateProjectSettings({
menuLogo: prefixFileUrlWithBackendUrl(menuLogo),
authLogo: prefixFileUrlWithBackendUrl(authLogo),
});

const deviceId = await getUID();

if (uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ describe('ADMIN | PAGES | AUTH | BaseLogin', () => {
alt=""
aria-hidden="true"
class="c6"
src="defaultAuthLogo.png"
src="customAuthLogo.png"
/>
<div
class="c1 c7"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ describe('ADMIN | PAGES | AUTH | Oops', () => {
alt=""
aria-hidden="true"
class="c15"
src="defaultAuthLogo.png"
src="customAuthLogo.png"
/>
<div
class="c0 c16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ describe('ADMIN | PAGES | AUTH | Register', () => {
alt=""
aria-hidden="true"
class="c15"
src="defaultAuthLogo.png"
src="customAuthLogo.png"
/>
<div
class="c0 c16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ describe('ADMIN | PAGES | AUTH | ResetPassword', () => {
alt=""
aria-hidden="true"
class="c15"
src="defaultAuthLogo.png"
src="customAuthLogo.png"
/>
<div
class="c0 c16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import { useTracking } from '@strapi/helper-plugin';
import { Grid, GridItem } from '@strapi/design-system/Grid';
import { Box } from '@strapi/design-system/Box';
import { Typography } from '@strapi/design-system/Typography';
import LogoInput from '../LogoInput';
import { useConfigurations } from '../../../../../../hooks';
import { DIMENSION, SIZE } from '../../utils/constants';
import LogoInput from '../LogoInput';
import reducer, { initialState } from './reducer';
import init from './init';

const Form = forwardRef(({ projectSettingsStored }, ref) => {
const Form = forwardRef(({ canUpdate, projectSettingsStored }, ref) => {
const { formatMessage } = useIntl();
const { trackUsage } = useTracking();
const {
logos: { menu },
logos: { menu, auth },
} = useConfigurations();
const [{ menuLogo }, dispatch] = useReducer(reducer, initialState, () =>
const [{ menuLogo, authLogo }, dispatch] = useReducer(reducer, initialState, () =>
init(initialState, projectSettingsStored)
);

Expand All @@ -28,15 +29,34 @@ const Form = forwardRef(({ projectSettingsStored }, ref) => {
};

const handleResetMenuLogo = () => {
trackUsage('didClickResetLogo');
trackUsage('didClickResetLogo', {
logo: 'menu',
});

dispatch({
type: 'RESET_CUSTOM_MENU_LOGO',
});
};

const handleChangeAuthLogo = (asset) => {
dispatch({
type: 'SET_CUSTOM_AUTH_LOGO',
value: asset,
});
};

const handleResetAuthLogo = () => {
trackUsage('didClickResetLogo', {
logo: 'auth',
});

dispatch({
type: 'RESET_CUSTOM_AUTH_LOGO',
});
};

useImperativeHandle(ref, () => ({
getValues: () => ({ menuLogo: menuLogo.submit }),
getValues: () => ({ menuLogo: menuLogo.submit, authLogo: authLogo.submit }),
}));

return (
Expand All @@ -55,13 +75,48 @@ const Form = forwardRef(({ projectSettingsStored }, ref) => {
defaultMessage: 'Customization',
})}
</Typography>
<Grid paddingTop={4}>
<Typography variant="pi" textColor="neutral600">
{formatMessage(
{
id: 'Settings.application.customization.size-details',
defaultMessage: 'Max dimension: {dimension}×{dimension}, Max file size: {size}KB',
},
{ dimension: DIMENSION, size: SIZE }
)}
</Typography>
<Grid paddingTop={4} gap={4}>
<GridItem col={6} s={12}>
<LogoInput
onChangeLogo={handleChangeMenuLogo}
canUpdate={canUpdate}
customLogo={menuLogo.display}
defaultLogo={menu.default}
onResetMenuLogo={handleResetMenuLogo}
hint={formatMessage({
id: 'Settings.application.customization.menu-logo.carousel-hint',
defaultMessage: 'Replace the logo in the main navigation',
})}
label={formatMessage({
id: 'Settings.application.customization.carousel.menu-logo.title',
defaultMessage: 'Menu logo',
})}
onChangeLogo={handleChangeMenuLogo}
onResetLogo={handleResetMenuLogo}
/>
</GridItem>
<GridItem col={6} s={12}>
<LogoInput
canUpdate={canUpdate}
customLogo={authLogo.display}
defaultLogo={auth.default}
hint={formatMessage({
id: 'Settings.application.customization.auth-logo.carousel-hint',
defaultMessage: 'Replace the logo in the authentication pages',
})}
label={formatMessage({
id: 'Settings.application.customization.carousel.auth-logo.title',
defaultMessage: 'Auth logo',
})}
onChangeLogo={handleChangeAuthLogo}
onResetLogo={handleResetAuthLogo}
/>
</GridItem>
</Grid>
Expand All @@ -70,10 +125,12 @@ const Form = forwardRef(({ projectSettingsStored }, ref) => {
});

Form.defaultProps = {
canUpdate: false,
projectSettingsStored: null,
};

Form.propTypes = {
canUpdate: PropTypes.bool,
projectSettingsStored: PropTypes.shape({
menuLogo: PropTypes.shape({
url: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const init = (initialState, projectSettingsStored) => {
menuLogo: {
display: projectSettingsStored.menuLogo,
},
authLogo: {
display: projectSettingsStored.authLogo,
},
});

return copyInitialState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const initialState = {
isReset: false,
},
},
authLogo: {
display: null,
submit: {
rawFile: null,
isReset: false,
},
},
};

const reducer = (state = initialState, action) =>
Expand All @@ -25,6 +32,11 @@ const reducer = (state = initialState, action) =>
draftState.menuLogo.submit.rawFile = action.value.rawFile;
break;
}
case 'SET_CUSTOM_AUTH_LOGO': {
draftState.authLogo.display = action.value;
draftState.authLogo.submit.rawFile = action.value.rawFile;
break;
}
case 'RESET_CUSTOM_MENU_LOGO': {
draftState.menuLogo.display = null;
draftState.menuLogo.submit = {
Expand All @@ -33,6 +45,14 @@ const reducer = (state = initialState, action) =>
};
break;
}
case 'RESET_CUSTOM_AUTH_LOGO': {
draftState.authLogo.display = null;
draftState.authLogo.submit = {
rawFile: null,
isReset: true,
};
break;
}
default: {
return draftState;
}
Expand Down