Skip to content

Commit

Permalink
Updated notification settings form schema to use object instead of ar…
Browse files Browse the repository at this point in the history
…ray, updated handlers to match, updated messages, need to finalize messages
  • Loading branch information
AndrewPhilbin committed Aug 22, 2023
1 parent 1f538a9 commit 36cad3c
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 82 deletions.
19 changes: 16 additions & 3 deletions src/components/Custom/RJSFFormFieldAdapter/RJSFFormFieldAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ export const CustomFieldTemplate = function(props) {
)
}

export const CustomNotificationFieldTemplate = function(props) {
const {classNames, children, description, uiSchema, errors} = props
return (
<div className={classNames}>
<React.Fragment>
<LabelWithHelp {...props} control />
{children}
{errors}
{description}
</React.Fragment>
</div>
)
}


/**
* A custom select widget with the new-ui styling
Expand Down Expand Up @@ -388,8 +402,7 @@ export const MarkdownDescriptionField = ({id, description}) => {
}

export const LabelWithHelp = props => {
const {id, displayLabel, label, required, rawHelp, schema, uiSchema} = props

const {id, displayLabel, label, required, control, rawHelp, schema, uiSchema} = props
if (displayLabel === false || uiSchema["ui:displayLabel"] === false) {
return null
}
Expand All @@ -403,7 +416,7 @@ export const LabelWithHelp = props => {

return (
<div className="mr-mb-2 mr-flex">
<label htmlFor={id} className="mr-text-mango mr-text-md mr-uppercase mr-mb-2">
<label htmlFor={id} className={control ? "mr-text-base mr-text-mango" : "mr-text-mango mr-text-md mr-uppercase mr-mb-2"}>
{normalizedLabel}
{required && <span className="mr-text-red-light mr-ml-1">*</span>}
</label>
Expand Down
10 changes: 10 additions & 0 deletions src/lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@
"Profile.form.addCustomBasemap.label": "Add Custom Basemap",
"Profile.form.allowFollowing.description": "If no, users will not be able to follow your MapRoulette activity.",
"Profile.form.allowFollowing.label": "Allow Following",
"Profile.form.challengeCompletedNotifications.description": "Receive a notification when a Challenge you created has been completed",
"Profile.form.customBasemap.description": "Insert a custom base map here. E.g. `https://'{s}'.tile.openstreetmap.org/'{z}'/'{x}'/'{y}'.png`",
"Profile.form.customBasemap.name.label": "Name",
"Profile.form.customBasemap.overlay.label": "is overlay?",
Expand All @@ -1170,6 +1171,7 @@
"Profile.form.email.description": "If you request emails in your Notification Subscriptions, they will be sent here.\n\nDecide which MapRoulette notifications you would like to receive, along with whether you would like to be sent an email informing you of the notification (either immediately or as a daily digest)",
"Profile.form.email.format": "email",
"Profile.form.email.label": "Email address",
"Profile.form.followNotifications.description": "This is a test follow help label",
"Profile.form.format.error": "should match format",
"Profile.form.isReviewer.description": "Volunteer to review tasks for which a review has been requested",
"Profile.form.isReviewer.label": "Volunteer as a Reviewer",
Expand All @@ -1178,15 +1180,23 @@
"Profile.form.locale.description": "User locale to use for MapRoulette UI.",
"Profile.form.locale.label": "Locale",
"Profile.form.mandatory.label": "Mandatory",
"Profile.form.mentionNotifications.description": "Receive a notification when someone @mentions you in a comment",
"Profile.form.metaReviewNotifications.description": "This is a test meta review help label",
"Profile.form.needsReview.description": "Automatically request a human review of each task you complete",
"Profile.form.needsReview.label": "Request Review of all Work",
"Profile.form.no.label": "No",
"Profile.form.notification.label": "Notification",
"Profile.form.notificationSubscriptions.description": "Decide which MapRoulette notifications you would like to receive, along with whether you would like to be sent an email informing you of the notification (either immediately or as a daily digest)",
"Profile.form.notificationSubscriptions.label": "Notification Subscriptions",
"Profile.form.reviewAgainNotifications.description": "This is a test review again notifications help label",
"Profile.form.reviewApprovedNotifications.description": "Receive a notification when your task was approved following a review",
"Profile.form.reviewCountNotifications.description": "This is a test review count help label",
"Profile.form.reviewRejectedNotifications.description": "Receive a notification when your task needs to be revisited following a review",
"Profile.form.revisionCountNotifications.description": "This is a test revise count help label",
"Profile.form.seeTagFixSuggestions.description": "User will see tag fix suggestions if they are provided.",
"Profile.form.seeTagFixSuggestions.label": "See Tag Fix Suggestions",
"Profile.form.systemNotifications.description": "This is a test system notifications help label",
"Profile.form.teamNotifications.description": "This is a test team notifications help label",
"Profile.form.uniqueCustomBasemap.error": "Custom Basemap names must be unique",
"Profile.form.yes.label": "Yes",
"Profile.noUser": "User not found or you are unauthorized to view this user.",
Expand Down
50 changes: 50 additions & 0 deletions src/pages/Profile/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,56 @@ export default defineMessages({
defaultMessage: "This is a test system notifications help label",
},

mentionNotificationsDescription: {
id: "Profile.form.mentionNotifications.description",
defaultMessage: "Receive a notification when someone @mentions you in a comment",
},

reviewApprovedNotificationsDescription: {
id: "Profile.form.reviewApprovedNotifications.description",
defaultMessage: "Receive a notification when your task was approved following a review",
},

reviewRejectedNotificationsDescription: {
id: "Profile.form.reviewRejectedNotifications.description",
defaultMessage: "Receive a notification when your task needs to be revisited following a review",
},

reviewAgainNotificationsDescription: {
id: "Profile.form.reviewAgainNotifications.description",
defaultMessage: "This is a test review again notifications help label",
},

challengeCompletedNotificationsDescription: {
id: "Profile.form.challengeCompletedNotifications.description",
defaultMessage: "Receive a notification when a Challenge you created has been completed",
},

teamNotificationsDescription: {
id: "Profile.form.teamNotifications.description",
defaultMessage: "This is a test team notifications help label",
},

followNotificationsDescription: {
id: "Profile.form.followNotifications.description",
defaultMessage: "This is a test follow help label",
},

metaReviewNotificationsDescription: {
id: "Profile.form.metaReviewNotifications.description",
defaultMessage: "This is a test meta review help label",
},

reviewCountNotificationsDescription: {
id: "Profile.form.reviewCountNotifications.description",
defaultMessage: "This is a test review count help label",
},

revisionCountNotificationsDescription: {
id: "Profile.form.revisionCountNotifications.description",
defaultMessage: "This is a test revise count help label",
},

yesLabel: {
id: "Profile.form.yes.label",
defaultMessage: "Yes",
Expand Down
113 changes: 81 additions & 32 deletions src/pages/Profile/UserSettings/NotificationSettingsSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "../../../services/Notification/NotificationSubscription/NotificationSubscription";
import MarkdownContent from "../../../components/MarkdownContent/MarkdownContent";
import messages from "../Messages";
import { CustomFieldTemplate } from '../../../components/Custom/RJSFFormFieldAdapter/RJSFFormFieldAdapter';
import { CustomNotificationFieldTemplate } from '../../../components/Custom/RJSFFormFieldAdapter/RJSFFormFieldAdapter';

const createSubscriptionInput = (
name,
Expand All @@ -27,19 +27,18 @@ const createSubscriptionInput = (
defaultSelection,
) => {
return {
name: name,
title: `${
notificationLabels[`${name}Long`] || notificationLabels[name]
} ${intl.formatMessage(messages.notificationLabel)}`,
type: "number",
enum: _values(subscriptionTypes),
enumNames: _map(subscriptionTypes, (value, key) => subscriptionLabels[key]),
default: defaultSelection,
};
};

name: name,
title: `${
notificationLabels[`${name}Long`] || notificationLabels[name]
} ${intl.formatMessage(messages.notificationLabel)}`,
type: "number",
enum: _values(subscriptionTypes),
enumNames: _map(subscriptionTypes, (value, key) => subscriptionLabels[key]),
default: defaultSelection,
}
}
export const transformErrors = (intl) => (errors) => {
console.log('errors', errors)
return errors.map(error => {
if (error.name === "format") {
const formatMessage = intl.formatMessage(messages.errorFormatMessage)
Expand Down Expand Up @@ -95,25 +94,34 @@ export const jsSchema = (intl) => {
);
});


// items are generated as array from all subscription and count types
const notificationObject = {}
items.forEach((item, i) => {
notificationObject[i] = item
items.filter(item => Boolean(item.name)).forEach((item) => {
notificationObject[item.name] = item
})

return {
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
properties: {
// notificationSubscriptions: {
// title: intl.formatMessage(messages.notificationSubscriptionsLabel),
// type: "array",
// items: items,
// },
notificationSubscriptions: {
title: intl.formatMessage(messages.notificationSubscriptionsLabel),
properties: notificationObject,
type: "object",
properties: {
system: notificationObject.system,
mention: notificationObject.mention,
reviewApproved: notificationObject.reviewApproved,
reviewRejected: notificationObject.reviewRejected,
reviewAgain: notificationObject.reviewAgain,
challengeCompleted: notificationObject.challengeCompleted,
team: notificationObject.team,
follow: notificationObject.follow,
metaReview: notificationObject.metaReview,
reviewCount: notificationObject.reviewCount,
revisionCount: notificationObject.revisionCount,
}
},

email: {
title: intl.formatMessage(messages.emailLabel),
type: "string",
Expand All @@ -134,6 +142,7 @@ export const jsSchema = (intl) => {
* > proper markup.
*/
export const uiSchema = (intl) => {

return {
email: {
classNames: "notification-email",
Expand All @@ -147,18 +156,58 @@ export const uiSchema = (intl) => {

notificationSubscriptions: {
classNames: "no-legend notification-subscriptions",
0: {
"ui:help": intl.formatMessage(messages.systemNotificationsDescription),
"ui:FieldTemplate": CustomFieldTemplate,
},
system: {
"ui:help": intl.formatMessage(messages.systemNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
"ui:options": {
orderable: false,
removable: false,
mention: {
"ui:help": intl.formatMessage(messages.mentionNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
"ui:order": ["email", "notificationSubscriptions"],
"ui:showTitle": false,

reviewApproved: {
"ui:help": intl.formatMessage(messages.reviewApprovedNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
reviewRejected: {
"ui:help": intl.formatMessage(messages.reviewRejectedNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
reviewAgain: {
"ui:help": intl.formatMessage(messages.reviewAgainNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
challengeCompleted: {
"ui:help": intl.formatMessage(messages.challengeCompletedNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
team: {
"ui:help": intl.formatMessage(messages.teamNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
follow: {
"ui:help": intl.formatMessage(messages.followNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
metaReview: {
"ui:help": intl.formatMessage(messages.metaReviewNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
reviewCount: {
"ui:help": intl.formatMessage(messages.reviewCountNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
revisionCount: {
"ui:help": intl.formatMessage(messages.revisionCountNotificationsDescription),
"ui:FieldTemplate": CustomNotificationFieldTemplate,
},
},

"ui:options": {
orderable: false,
removable: false,
},
"ui:order": ["email", "notificationSubscriptions"],
"ui:showTitle": false,
};
};

Expand Down
Loading

0 comments on commit 36cad3c

Please sign in to comment.