Skip to content

feat: add slot to extend the profile fields #1211

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@fortawesome/free-regular-svg-icons": "6.7.2",
"@fortawesome/free-solid-svg-icons": "6.7.2",
"@fortawesome/react-fontawesome": "0.2.2",
"@openedx/frontend-plugin-framework": "^1.7.0",
"@openedx/paragon": "^23.4.5",
"@pact-foundation/pact": "^11.0.2",
"@redux-devtools/extension": "3.3.0",
Expand Down
49 changes: 49 additions & 0 deletions src/plugin-slots/ExtendedProfileFieldsSlot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Extended Profile Fields

### Slot ID: `org.openedx.frontend.profile.extended_profile_fields.v1`

### Slot ID Aliases
* `extended_profile_fields_slot`

## Description

This slot is used to replace/modify/hide the extended profile fields in the account page.

## Example

> [!NOTE]
> Take into account that the fields shown in the screenshots come from a [custom NPM Package](https://www.npmjs.com/package/@edunext/frontend-component-extended-fields)

The following `env.config.jsx` will replace the default custom fields.

![Screenshot of Default Fields](./images/default_fields.png)

with a custom extended fields component

![Screenshot of Custom Fields](./images/custom_fields.png)

```jsx
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';

import { ExtendedProfileFields } from '@organization/frontend-component-extended-fields';

const config = {
pluginSlots: {
extended_profile_fields_slot: {
keepDefault: false,
plugins: [
{
op: PLUGIN_OPERATIONS.Insert,
widget: {
id: 'extended_profile_fields',
type: DIRECT_PLUGIN,
RenderWidget: ExtendedProfileFields,
},
},
],
},
},
};

export default config;
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions src/plugin-slots/ExtendedProfileFieldsSlot/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PluginSlot } from '@openedx/frontend-plugin-framework';
import { useDispatch, useSelector } from 'react-redux';

import { useCallback } from 'react';
import { patchProfile } from '../../profile/data/services';
import { fetchProfile } from '../../profile/data/actions';

import SwitchContent from '../../profile/forms/elements/SwitchContent';
import EmptyContent from '../../profile/forms/elements/EmptyContent';
import EditableItemHeader from '../../profile/forms/elements/EditableItemHeader';

const ExtendedProfileFieldsSlot = () => {
const dispatch = useDispatch();
const extendedProfileValues = useSelector((state) => state.profilePage.account.extendedProfile);

const pluginProps = {
refreshUserProfile: useCallback((username) => dispatch(fetchProfile(username)), [dispatch]),
updateUserProfile: patchProfile,
profileFieldValues: extendedProfileValues,
formComponents: {
SwitchContent,
EmptyContent,
EditableItemHeader,
},
};

return (
<PluginSlot
id="org.openedx.frontend.profile.extended_profile_fields.v1"
idAliases={['extended_profile_fields_slot']}
pluginProps={pluginProps}
/>
);
};

export default ExtendedProfileFieldsSlot;
6 changes: 6 additions & 0 deletions src/profile/ProfilePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
import { InfoOutline } from '@openedx/paragon/icons';
import classNames from 'classnames';

import ExtendedProfileFieldsSlot from '../plugin-slots/ExtendedProfileFieldsSlot';

// Actions
import {
fetchProfile,
saveProfile,
Expand Down Expand Up @@ -362,6 +365,9 @@ const ProfilePage = ({ params }) => {
{...commonFormProps}
/>
)}

<ExtendedProfileFieldsSlot />

{isBlockVisible((socialLinks || []).some((link) => link?.socialLink !== null)) && (
<SocialLinks
socialLinks={socialLinks || []}
Expand Down