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

CM-854: display missing config dialog #2

Merged
merged 3 commits into from
Apr 8, 2024
Merged
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
15 changes: 13 additions & 2 deletions src/actions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import {
graphql, formatMutation, formatPageQueryWithCount, formatGQLString, formatPageQuery,
baseApiUrl, decodeId, openBlob
baseApiUrl, decodeId, openBlob, formatQuery,
} from "@openimis/fe-core";

Check failure on line 4 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
import {ACTION_TYPE} from "./reducer";

Check failure on line 5 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

A space is required after '{'

Check failure on line 5 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

A space is required before '}'

Check failure on line 5 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote

const GRIEVANCE_CONFIGURATION_PROJECTION = () => [
'grievanceTypes',
'grievanceFlags',
'grievanceChannels',
];

const CATEGORY_FULL_PROJECTION = (mm) => [

Check failure on line 13 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

'mm' is defined but never used
"id",

Check failure on line 14 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
"uuid",

Check failure on line 15 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
"categoryTitle",

Check failure on line 16 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
"slug",

Check failure on line 17 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
"validityFrom",

Check failure on line 18 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

Strings must use singlequote
"validityTo",
];

Expand Down Expand Up @@ -149,7 +156,7 @@
}

export function createTicketAttachment(ticketattachment, clientMutationLabel) {
console.log("_ _ _ _ _ _ _ _ _ _", ticketattachment);

Check warning on line 159 in src/actions.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
let mutation = formatMutation("createTicketAttachment", formatTicketAttachmentGQL(ticketattachment), clientMutationLabel);
var requestedDateTime = new Date();
return graphql(mutation.payload, ["TICKET_ATTACHMENT_MUTATION_REQ", "TICKET_CREATE_TICKET_ATTACHMENT_RESP", "TICKET_ATTACHMENT_MUTATION_ERR"], {
Expand Down Expand Up @@ -212,7 +219,6 @@
return graphql(payload, 'TICKET_TICKET');
}


export function fetchInsureeTickets(mm, filters) {
if (filters.filter((f) => f.startsWith("chfId")).length !== 0) {
qry = "ticketsByInsuree";
Expand All @@ -225,3 +231,8 @@
);
return graphql(payload, RDX);
}

export function fetchGrievanceConfiguration(params) {
const payload = formatQuery('grievanceConfig', params, GRIEVANCE_CONFIGURATION_PROJECTION())
return graphql(payload, ACTION_TYPE.GET_GRIEVANCE_CONFIGURATION);
}
8 changes: 5 additions & 3 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const TICKET_STATUS = ["Waiting", "Todo", "Inprogress", "Review", "Close"]
export const TICKET_STATUS = ['Waiting', 'Todo', 'Inprogress', 'Review', 'Close'];

export const TICKET_PRIORITY = ["Critical", "High", "Normal", "Low"]
export const TICKET_PRIORITY = ['Critical', 'High', 'Normal', 'Low'];

export const RIGHT_TICKET = 123000;
export const RIGHT_TICKET_SEARCH = 123000;
export const RIGHT_TICKET_ADD = 123001;
export const RIGHT_TICKET_EDIT = 123002;
export const RIGHT_TICKET_DELETE = 123003;
export const RIGHT_TICKET_DELETE = 123003;

export const MODULE_NAME = 'grievanceSocialProtection';
68 changes: 68 additions & 0 deletions src/dialogs/GrievanceConfigurationDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
coreAlert,
useModulesManager,
useTranslations,
} from '@openimis/fe-core';
import { fetchGrievanceConfiguration } from '../actions';
import {
MODULE_NAME,
RIGHT_TICKET,
RIGHT_TICKET_ADD,
RIGHT_TICKET_DELETE,
RIGHT_TICKET_EDIT,
RIGHT_TICKET_SEARCH,
} from '../constants';

function GrievanceConfigurationDialog({
rights,
}) {
const modulesManager = useModulesManager();
const { formatMessage, formatMessageWithValues } = useTranslations(MODULE_NAME, modulesManager);
const dispatch = useDispatch();
const grievanceConfiguration = useSelector((state) => state?.grievanceSocialProtection?.grievanceConfig);
const fetchedGrievanceConfig = useSelector((state) => state?.grievanceSocialProtection?.fetchedGrievanceConfig);

const doesUserHaveRights = () => {
const rightsArray = [
RIGHT_TICKET,
RIGHT_TICKET_SEARCH,
RIGHT_TICKET_ADD,
RIGHT_TICKET_EDIT,
RIGHT_TICKET_DELETE,
];
return rightsArray.every((right) => rights.includes(right));
};
const isMatchingConfigObject = (obj) => !(typeof obj !== 'object' || obj === null || Array.isArray(obj));

const isConfigMissing = (config) => Object.values(config).some((field) => !field);

const shouldDisplay = () => grievanceConfiguration
&& doesUserHaveRights()
&& isMatchingConfigObject(grievanceConfiguration)
&& isConfigMissing(grievanceConfiguration);

useEffect(() => {
if (shouldDisplay()) {
const configString = JSON.stringify(grievanceConfiguration);
dispatch(coreAlert(
formatMessage('grievanceSocialProtection.dialogs.GrievanceConfigurationDialog.dialogHeader'),
formatMessageWithValues(
'grievanceSocialProtection.dialogs.GrievanceConfigurationDialog.dialogBody',
{ configString },
),
));
}
}, [grievanceConfiguration]);

useEffect(() => {
if (!fetchedGrievanceConfig) {
dispatch(fetchGrievanceConfiguration());
}
}, [fetchedGrievanceConfig]);

return null;
}

export default GrievanceConfigurationDialog;
78 changes: 40 additions & 38 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
import React from "react";
import messages_en from "./translations/en.json";
import reducer from "./reducer";
import { ListAlt } from "@material-ui/icons";
import { FormattedMessage } from "@openimis/fe-core";
import TicketMainMenu from "./menu/TicketMainMenu";
import TicketsPage from "./pages/TicketsPage";
import TicketPage from "./pages/TicketPage";
import TicketSearcher from "./components/TicketSearcher";
import TicketPriorityPicker from "./pickers/TicketPriorityPicker";
import TicketStatusPicker from "./pickers/TicketStatusPicker";
import DropDownCategoryPicker from "./pickers/DropDownCategoryPicker";
import CategoryPicker from "./pickers/CategoryPicker";

const ROUTE_TICKET_TICKETS = "ticket/tickets";
const ROUTE_TICKET_TICKET = "ticket/ticket";
// Disable due to core architecture
/* eslint-disable camelcase */
/* eslint-disable import/prefer-default-export */
import React from 'react';
import { ListAlt } from '@material-ui/icons';
import { FormattedMessage } from '@openimis/fe-core';
import messages_en from './translations/en.json';
import reducer from './reducer';
import TicketMainMenu from './menu/TicketMainMenu';
import TicketsPage from './pages/TicketsPage';
import TicketPage from './pages/TicketPage';
import TicketSearcher from './components/TicketSearcher';
import TicketPriorityPicker from './pickers/TicketPriorityPicker';
import TicketStatusPicker from './pickers/TicketStatusPicker';
import DropDownCategoryPicker from './pickers/DropDownCategoryPicker';
import CategoryPicker from './pickers/CategoryPicker';
import GrievanceConfigurationDialog from './dialogs/GrievanceConfigurationDialog';
import { MODULE_NAME } from './constants';

const ROUTE_TICKET_TICKETS = 'ticket/tickets';
const ROUTE_TICKET_TICKET = 'ticket/ticket';

const DEFAULT_CONFIG = {
"translations": [{ key: "en", messages: messages_en }],
"reducers": [{ key: 'grievance', reducer }],
translations: [{ key: 'en', messages: messages_en }],
reducers: [{ key: 'grievanceSocialProtection', reducer }],

"refs": [
{ key: "grievance.route.tickets", ref: ROUTE_TICKET_TICKETS },
{ key: "grievance.route.ticket", ref: ROUTE_TICKET_TICKET },
refs: [
{ key: 'grievanceSocialProtection.route.tickets', ref: ROUTE_TICKET_TICKETS },
{ key: 'grievanceSocialProtection.route.ticket', ref: ROUTE_TICKET_TICKET },

{ key: "grievance.route.ticketSearcher", ref: TicketSearcher },
{ key: 'grievanceSocialProtection.route.ticketSearcher', ref: TicketSearcher },

{ key: "grievance.TicketStatusPicker", ref: TicketStatusPicker },
{ key: "grievance.TicketPriorityPicker", ref: TicketPriorityPicker },
{ key: "grievance.DropDownCategoryPicker", ref: DropDownCategoryPicker },
{ key: "grievance.CategoryPicker", ref: CategoryPicker },
{ key: 'grievanceSocialProtection.TicketStatusPicker', ref: TicketStatusPicker },
{ key: 'grievanceSocialProtection.TicketPriorityPicker', ref: TicketPriorityPicker },
{ key: 'grievanceSocialProtection.DropDownCategoryPicker', ref: DropDownCategoryPicker },
{ key: 'grievanceSocialProtection.CategoryPicker', ref: CategoryPicker },
{ key: 'grievanceSocialProtection.GrievanceConfigurationDialog', ref: GrievanceConfigurationDialog },

],
"core.Router": [
'core.Router': [
{ path: ROUTE_TICKET_TICKETS, component: TicketsPage },
{ path: ROUTE_TICKET_TICKET+ "/:ticket_uuid?", component: TicketPage },
{ path: `${ROUTE_TICKET_TICKET}/:ticket_uuid?`, component: TicketPage },
],

"admin.MainMenu": [
'admin.MainMenu': [
{
text: <FormattedMessage module="grievance" id="menu.ticket" />,
text: <FormattedMessage module={MODULE_NAME} id="menu.ticket" />,
icon: <ListAlt />,
route: "/" + ROUTE_TICKET_TICKETS,
route: `/${ROUTE_TICKET_TICKETS}`,
},
],
"core.MainMenu": [TicketMainMenu],


}
'core.MainMenu': [TicketMainMenu],

export const GrievanceSocialProtectionModule = (cfg) => {
return { ...DEFAULT_CONFIG, ...cfg };
}
};

export const GrievanceSocialProtectionModule = (cfg) => ({ ...DEFAULT_CONFIG, ...cfg });
Loading
Loading