Skip to content

Commit

Permalink
#1189 - no sync settings for STT.User and not subject type is not edi…
Browse files Browse the repository at this point in the history
…table
  • Loading branch information
petmongrels committed Apr 12, 2024
1 parent 8c75f2f commit 98fb984
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 74 deletions.
91 changes: 39 additions & 52 deletions src/adminApp/SubjectType/AdvancedSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { forEach, get, includes, isEmpty } from "lodash";
import { OptionSelect } from "./OptionSelect";
import { Accordion, AccordionDetails, Box, Input } from "@material-ui/core";
import { AvniFormLabel } from "../../common/components/AvniFormLabel";
import { SubjectTypeType } from "./Types";

const CustomAccordion = withStyles({
root: {
Expand All @@ -34,18 +35,11 @@ const CustomAccordianDetails = withStyles(theme => ({
CustomAccordianDetails.muiName = "AccordionDetails";

const syncAttributeDataTypes = ["Numeric", "Coded", "Text"];
export const AdvancedSettings = ({
subjectType,
dispatch,
locationTypes,
formMappings,
isEdit
}) => {
export const AdvancedSettings = ({ subjectType, dispatch, locationTypes, formMappings, isEdit }) => {
const [expanded, setExpanded] = React.useState(false);
const [syncAttributes, setSyncAttributes] = React.useState([]);
const formUuid = findFormUuidForSubjectType(subjectType, formMappings);
const changeSyncAttribute = (name, value) =>
dispatch({ type: "syncAttribute", payload: { name, value } });
const changeSyncAttribute = (name, value) => dispatch({ type: "syncAttribute", payload: { name, value } });

const onSyncConceptChange = (name, value) => {
const syncAttributeChangeMessage =
Expand All @@ -65,12 +59,7 @@ export const AdvancedSettings = ({
forEach(form.formElementGroups, feg => {
forEach(feg.formElements, fe => {
const concept = fe.concept;
if (
!feg.voided &&
!fe.voided &&
fe.mandatory &&
includes(syncAttributeDataTypes, concept.dataType)
) {
if (!feg.voided && !fe.voided && fe.mandatory && includes(syncAttributeDataTypes, concept.dataType)) {
syncAttributes.push({ label: concept.name, value: concept.uuid });
}
});
Expand All @@ -95,9 +84,7 @@ export const AdvancedSettings = ({
<AvniSwitch
switchFirst
checked={!!subjectType.allowEmptyLocation}
onChange={event =>
dispatch({ type: "allowEmptyLocation", payload: event.target.checked })
}
onChange={event => dispatch({ type: "allowEmptyLocation", payload: event.target.checked })}
name="Allow Empty Location"
toolTipKey={"APP_DESIGNER_SUBJECT_TYPE_ALLOW_EMPTY_LOCATION"}
/>
Expand All @@ -111,9 +98,7 @@ export const AdvancedSettings = ({
<AvniSwitch
switchFirst
checked={!!subjectType.allowProfilePicture}
onChange={event =>
dispatch({ type: "allowProfilePicture", payload: event.target.checked })
}
onChange={event => dispatch({ type: "allowProfilePicture", payload: event.target.checked })}
name="Allow Profile Picture"
toolTipKey={"APP_DESIGNER_SUBJECT_TYPE_ALLOW_PROFILE_PICTURE"}
/>
Expand All @@ -124,11 +109,7 @@ export const AdvancedSettings = ({
regexLabel={subjectType.type === "Person" ? "First Name Regex" : "Name Regex"}
regexToolTipKey={"APP_DESIGNER_FIRST_NAME_REGEX"}
regexID={"validFirstNameRegex"}
descKeyLabel={
subjectType.type === "Person"
? "First Name Validation Description Key"
: "Name Validation Description Key"
}
descKeyLabel={subjectType.type === "Person" ? "First Name Validation Description Key" : "Name Validation Description Key"}
descToolTipKey={"APP_DESIGNER_FIRST_NAME_DESCRIPTION_KEY"}
descID={"validFirstNameDescriptionKey"}
propertyName={"validFirstNameFormat"}
Expand Down Expand Up @@ -228,32 +209,38 @@ export const AdvancedSettings = ({
<Typography gutterBottom variant={"subtitle1"}>
{"Sync Settings"}
</Typography>
<AvniSwitch
switchFirst
checked={!!subjectType.shouldSyncByLocation}
onChange={event => changeSyncAttribute("shouldSyncByLocation", event.target.checked)}
name="Sync by location"
toolTipKey={"APP_DESIGNER_SUBJECT_TYPE_SYC_BY_LOCATION"}
/>
<AvniSwitch
switchFirst
checked={!!subjectType.directlyAssignable}
onChange={event => changeSyncAttribute("directlyAssignable", event.target.checked)}
name="Sync by direct assignment"
toolTipKey={"APP_DESIGNER_SUBJECT_TYPE_SYNC_BY_DIRECT_ASSIGNMENT"}
/>
<OptionSelect
label={"Sync Registration Concept 1"}
options={syncAttributes}
value={subjectType.syncRegistrationConcept1}
onChange={value => onSyncConceptChange("syncRegistrationConcept1", value)}
/>
<OptionSelect
label={"Sync Registration Concept 2"}
options={syncAttributes}
value={subjectType.syncRegistrationConcept2}
onChange={value => onSyncConceptChange("syncRegistrationConcept2", value)}
/>
{subjectType.type === SubjectTypeType.User ? (
<Typography>Determined by Subject Type</Typography>
) : (
<>
<AvniSwitch
switchFirst
checked={!!subjectType.shouldSyncByLocation}
onChange={event => changeSyncAttribute("shouldSyncByLocation", event.target.checked)}
name="Sync by location"
toolTipKey={"APP_DESIGNER_SUBJECT_TYPE_SYC_BY_LOCATION"}
/>
<AvniSwitch
switchFirst
checked={!!subjectType.directlyAssignable}
onChange={event => changeSyncAttribute("directlyAssignable", event.target.checked)}
name="Sync by direct assignment"
toolTipKey={"APP_DESIGNER_SUBJECT_TYPE_SYNC_BY_DIRECT_ASSIGNMENT"}
/>
<OptionSelect
label={"Sync Registration Concept 1"}
options={syncAttributes}
value={subjectType.syncRegistrationConcept1}
onChange={value => onSyncConceptChange("syncRegistrationConcept1", value)}
/>
<OptionSelect
label={"Sync Registration Concept 2"}
options={syncAttributes}
value={subjectType.syncRegistrationConcept2}
onChange={value => onSyncConceptChange("syncRegistrationConcept2", value)}
/>
</>
)}
</Box>
</div>
</CustomAccordianDetails>
Expand Down
41 changes: 20 additions & 21 deletions src/adminApp/SubjectType/SubjectTypeEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { MessageReducer } from "../../formDesigner/components/MessageRule/Messag
import { getMessageRules, getMessageTemplates, saveMessageRules } from "../service/MessageService";
import MessageRules from "../../formDesigner/components/MessageRule/MessageRules";
import { connect } from "react-redux";
import { SubjectTypeType } from "./Types";

const SubjectTypeEdit = ({ organisationConfig, ...props }) => {
const [subjectType, dispatch] = useReducer(subjectTypeReducer, subjectTypeInitialState);
Expand Down Expand Up @@ -87,11 +88,7 @@ const SubjectTypeEdit = ({ organisationConfig, ...props }) => {

setNameValidation(false);
if (!groupValidationError) {
const [s3FileKey, error] = await uploadImage(
subjectType.iconFileS3Key,
file,
bucketName.ICONS
);
const [s3FileKey, error] = await uploadImage(subjectType.iconFileS3Key, file, bucketName.ICONS);
if (error) {
alert(error);
return;
Expand Down Expand Up @@ -140,21 +137,15 @@ const SubjectTypeEdit = ({ organisationConfig, ...props }) => {
}
};

if (
!_.isEmpty(formMappings) &&
!_.isEmpty(subjectType.uuid) &&
!firstTimeFormValueToggle &&
_.isEmpty(subjectType.registrationForm)
) {
if (!_.isEmpty(formMappings) && !_.isEmpty(subjectType.uuid) && !firstTimeFormValueToggle && _.isEmpty(subjectType.registrationForm)) {
setFirstTimeFormValueToggle(true);
let payload = findRegistrationForm(formMappings, subjectType);
dispatch({ type: "registrationForm", payload: payload });
}

const disableDelete = _.find(
subjectTypes,
({ group, memberSubjectUUIDs }) =>
group && _.includes(memberSubjectUUIDs.split(","), subjectType.uuid)
({ group, memberSubjectUUIDs }) => group && _.includes(memberSubjectUUIDs.split(","), subjectType.uuid)
);

return (
Expand All @@ -167,14 +158,22 @@ const SubjectTypeEdit = ({ organisationConfig, ...props }) => {
</Button>
</Grid>
<div className="container" style={{ float: "left" }}>
<EditSubjectTypeFields
subjectType={subjectType}
onSetFile={setFile}
onRemoveFile={setRemoveFile}
formList={formList}
groupValidationError={groupValidationError}
dispatch={dispatch}
/>
{subjectType.type === SubjectTypeType.User ? (
<div>
<FormLabel style={{ fontSize: "13px" }}>Type</FormLabel>
<br />
<span style={{ fontSize: "15px" }}>{subjectType.type}</span>
</div>
) : (
<EditSubjectTypeFields
subjectType={subjectType}
onSetFile={setFile}
onRemoveFile={setRemoveFile}
formList={formList}
groupValidationError={groupValidationError}
dispatch={dispatch}
/>
)}
{organisationConfig && organisationConfig.enableMessaging ? (
<MessageRules
rules={rules}
Expand Down
6 changes: 5 additions & 1 deletion src/common/model/WebSubjectType.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ function getRole(role, minimumNumberOfMembers, maximumNumberOfMembers) {

class WebSubjectType {
static updateType(subjectType, type) {
if (type === SubjectTypeType.User) subjectType.allowEmptyLocation = true;
if (type === SubjectTypeType.User) {
subjectType.allowEmptyLocation = true;
subjectType.shouldSyncByLocation = false;
subjectType.directlyAssignable = false;
}
if (!Types.isGroup(type)) {
return { ...subjectType, type, groupRoles: [] };
}
Expand Down

0 comments on commit 98fb984

Please sign in to comment.