Skip to content

Commit

Permalink
poc to use a custom component from a plugin INTO a Iaso page
Browse files Browse the repository at this point in the history
  • Loading branch information
beygorghor committed Jan 31, 2025
1 parent 047c21f commit 2fcacbc
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 2 deletions.
4 changes: 4 additions & 0 deletions hat/assets/js/apps/Iaso/domains/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export type Plugin = {
baseUrls: Record<string, string>;
paramsConfig: Record<string, string[]>;
redirections?: RoutingRedirection[];
customComponents?: {
key: string;
component: ElementType;
}[];
};

export type Plugins = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const ReviewOrgUnitFieldChanges: FunctionComponent<Props> = ({
const isSelected =
(status && field?.isSelected === true && 'success.light') || '';

console.log('fieldValues', fieldValues);
return (
<Accordion defaultExpanded>
<AccordionSummary
Expand All @@ -50,7 +51,6 @@ export const ReviewOrgUnitFieldChanges: FunctionComponent<Props> = ({
value.right === false)) &&
'error.light') ||
'';

return (
<TableRow key={value.id}>
<TableCell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export const ReviewOrgUnitChangesDetailsTableBody: FunctionComponent<Props> = ({
changeRequest && changeRequest[`new_${field.key}`];
const changedFieldWithOldValues =
changeRequest && changeRequest[`old_${field.key}`];

console.log(
'changedFieldWithOldValues',
changedFieldWithOldValues,
);
return (
<HighlightFields
key={key}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ export const ReviewOrgUnitChangesDetail: FunctionComponent = () => {

const { data: changeRequest, isFetching: isFetchingChangeRequest } =
useGetApprovalProposal(Number(params.changeRequestId));
console.log('changeRequest', changeRequest);
const isNew: boolean =
!isFetchingChangeRequest && changeRequest?.status === 'new';
const isNewOrgUnit = changeRequest
? changeRequest.org_unit.validation_status === 'NEW'
: false;
const { newFields, setSelected } = useNewFields(changeRequest);
console.log('newFields', newFields);
const goBack = useGoBack(baseUrls.orgUnitsChangeRequest);
const titleMessage = useMemo(() => {
if (changeRequest?.status === 'rejected') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ export const useNewFields = (
fieldKey,
value,
);
console.log('key', key);
console.log('oldValue', oldValue);
console.log('newValue', newValue);
console.log('isChanged', isChanged);
const { label, order, fieldType } = fieldDef;
return {
key: fieldKey,
Expand Down
25 changes: 25 additions & 0 deletions hat/assets/js/apps/Iaso/domains/users/components/UsersDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import React, {
FunctionComponent,
useCallback,
useContext,
useEffect,
useMemo,
useState,
Expand All @@ -18,8 +19,10 @@ import React, {
import { MutateFunction, useQueryClient } from 'react-query';

import { EditIconButton } from '../../../components/Buttons/EditIconButton';
import { PluginsContext } from '../../../utils';
import * as Permissions from '../../../utils/permissions';
import { Profile, useCurrentUser } from '../../../utils/usersUtils';
import { Plugins } from '../../app/types';
import MESSAGES from '../messages';
import { InitialUserData } from '../types';
import PermissionsAttribution from './PermissionsAttribution';
Expand Down Expand Up @@ -170,6 +173,13 @@ const UserDialogComponent: FunctionComponent<Props> = ({
];
}, [allUserRolesPermissions, user.user_permissions.value]);

const { plugins }: Plugins = useContext(PluginsContext);
// Find the custom tab component if it exists
const customUserTab = plugins[0].customComponents?.find(
comp => comp.key === 'user.extraTab',
);
console.log('customUserTab', customUserTab);

useEffect(() => {
setHasNoOrgUnitManagementWrite(
!allUserUserRolesPermissions.includes(Permissions.ORG_UNITS),
Expand Down Expand Up @@ -253,6 +263,15 @@ const UserDialogComponent: FunctionComponent<Props> = ({
label={formatMessage(MESSAGES.orgUnitWriteTypes)}
/>
)}
{customUserTab && (
<Tab
classes={{
root: classes.tab,
}}
value="customTab"
label="Custom Tab"
/>
)}
</Tabs>
<div className={classes.root} id="user-profile-dialog">
<div
Expand Down Expand Up @@ -298,6 +317,12 @@ const UserDialogComponent: FunctionComponent<Props> = ({
}
/>
)}
{tab === 'customTab' && customUserTab && (
<customUserTab.component
currentUser={user}
setFieldValue={setFieldValue}
/>
)}
</div>
</ConfirmCancelModal>
</>
Expand Down
7 changes: 7 additions & 0 deletions plugins/registry/js/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { routes } from './src/constants/routes';
import en from './src/constants/translations/en.json';
import fr from './src/constants/translations/fr.json';
import { baseUrls, paramsConfig } from './src/constants/urls';
import { UserTab } from './userTab';

const translations = {
fr,
Expand All @@ -16,6 +17,12 @@ const config: Plugin = {
redirections: [],
menu: [],
translations,
customComponents: [
{
key: 'user.extraTab',
component: UserTab,
},
],
};

export default config;
18 changes: 18 additions & 0 deletions plugins/registry/js/userTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Box, Typography } from '@mui/material';
import React, { FC } from 'react';

interface UserTabProps {
currentUser: any; // You can replace 'any' with your specific user type
setFieldValue: (key: string, value: any) => void;
// Add any other props you need
}

export const UserTab: FC<UserTabProps> = ({ currentUser, setFieldValue }) => {
console.log('currentUser', currentUser);
return (
<Box>
<Typography>CECI VIENt DE REGISTRY</Typography>
{/* Use your props here */}
</Box>
);
};

0 comments on commit 2fcacbc

Please sign in to comment.