Skip to content

Commit

Permalink
fix: catch up fixes v38 [DHIS2-15524] (#1288)
Browse files Browse the repository at this point in the history
* fix: address various style and text issues

* fix: close action menu when closing confirmation modal

---------

Co-authored-by: HendrikThePendric <[email protected]>
  • Loading branch information
tomzemp and HendrikThePendric authored Sep 14, 2023
1 parent fb8948c commit 017a876
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 29 deletions.
24 changes: 15 additions & 9 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2022-06-13T10:12:52.361Z\n"
"PO-Revision-Date: 2022-06-13T10:12:52.361Z\n"
"POT-Creation-Date: 2023-08-02T13:20:46.717Z\n"
"PO-Revision-Date: 2023-08-02T13:20:46.717Z\n"

msgid "Yes"
msgstr "Yes"
Expand Down Expand Up @@ -560,6 +560,12 @@ msgstr "Invalid username"
msgid "Invalid WhatsApp number"
msgstr "Invalid WhatsApp number"

msgid "Send invite"
msgstr "Send invite"

msgid "Cancel invite"
msgstr "Cancel invite"

msgid "Error updating user"
msgstr "Error updating user"

Expand Down Expand Up @@ -918,11 +924,8 @@ msgstr "Password of user \"{{- name}}\" reset successfuly"
msgid "There was an error resetting the password: {{- error}}"
msgstr "There was an error resetting the password: {{- error}}"

msgid "Reset password of user {{- name}}"
msgstr "Reset password of user {{- name}}"

msgid "Are you sure you want to reset {{- name}}'s password?"
msgstr "Are you sure you want to reset {{- name}}'s password?"
msgid "Are you sure you want to reset the password for {{- name}}?"
msgstr "Are you sure you want to reset the password for {{- name}}?"

msgid "Yes, reset"
msgstr "Yes, reset"
Expand Down Expand Up @@ -960,11 +963,14 @@ msgstr "User Management"
msgid "Error loading users"
msgstr "Error loading users"

msgid "Account disabled?"
msgstr "Account disabled?"
msgid "Status"
msgstr "Status"

msgid "Disabled"
msgstr "Disabled"

msgid "Active"
msgstr "Active"

msgid "Something went wrong when processing your request."
msgstr "Something went wrong when processing your request."
16 changes: 14 additions & 2 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,14 @@ TransferField.propTypes = {
required: PropTypes.bool,
}

const Form = ({ loading, error, children, submitButtonLabel, onSubmit }) => {
const Form = ({
loading,
error,
children,
submitButtonLabel,
cancelButtonLabel,
onSubmit,
}) => {
const history = useHistory()
const handleCancel = () => history.goBack()

Expand Down Expand Up @@ -331,7 +338,7 @@ const Form = ({ loading, error, children, submitButtonLabel, onSubmit }) => {
{submitButtonLabel}
</Button>
<Button onClick={handleCancel} disabled={submitting}>
{i18n.t('Cancel without saving')}
{cancelButtonLabel}
</Button>
</ButtonStrip>
</form>
Expand All @@ -340,10 +347,15 @@ const Form = ({ loading, error, children, submitButtonLabel, onSubmit }) => {
)
}

Form.defaultProps = {
cancelButtonLabel: i18n.t('Cancel without saving'),
}

Form.propTypes = {
children: PropTypes.func.isRequired,
submitButtonLabel: PropTypes.string.isRequired,
onSubmit: PropTypes.func.isRequired,
cancelButtonLabel: PropTypes.string,
error: PropTypes.instanceOf(Error),
loading: PropTypes.bool,
}
Expand Down
14 changes: 12 additions & 2 deletions src/components/UserForm/InviteUserSection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React from 'react'
import React, { useEffect } from 'react'
import { useField } from 'react-final-form'
import { FormSection, SingleSelectField } from '../Form'

const InviteUserSection = ({ user, emailConfigured }) => {
const InviteUserSection = ({ user, emailConfigured, setIsInvite }) => {
const {
input: { value },
} = useField('inviteUser', { subscription: { value: true } })

useEffect(() => {
setIsInvite(value === 'INVITE_USER')
}, [value, setIsInvite])

if (user || !emailConfigured) {
return null
}
Expand Down Expand Up @@ -31,6 +40,7 @@ const InviteUserSection = ({ user, emailConfigured }) => {

InviteUserSection.propTypes = {
emailConfigured: PropTypes.bool,
setIsInvite: PropTypes.func,
user: PropTypes.object,
}

Expand Down
13 changes: 11 additions & 2 deletions src/components/UserForm/UserForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import i18n from '@dhis2/d2-i18n'
import { NoticeBox, FinalForm } from '@dhis2/ui'
import { keyBy } from 'lodash-es'
import PropTypes from 'prop-types'
import React from 'react'
import React, { useState } from 'react'
import { useHistory } from 'react-router-dom'
import { useCurrentUser } from '../../hooks/useCurrentUser'
import Attributes from '../Attributes'
Expand All @@ -28,6 +28,7 @@ const UserForm = ({
const {
systemInfo: { emailConfigured },
} = useConfig()
const [isInvite, setIsInvite] = useState(false)
const history = useHistory()
const engine = useDataEngine()
const {
Expand Down Expand Up @@ -133,7 +134,14 @@ const UserForm = ({
<Form
loading={loading}
error={error}
submitButtonLabel={submitButtonLabel}
submitButtonLabel={
isInvite ? i18n.t('Send invite') : submitButtonLabel
}
cancelButtonLabel={
isInvite
? i18n.t('Cancel invite')
: i18n.t('Cancel without saving')
}
onSubmit={handleSubmit}
>
{({ values, submitError }) => (
Expand All @@ -154,6 +162,7 @@ const UserForm = ({
<InviteUserSection
user={user}
emailConfigured={emailConfigured}
setIsInvite={setIsInvite}
/>
<BasicInformationSection
user={user}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/GroupList/ContextMenu/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ const ContextMenu = ({
<CurrentModal
group={group}
refetchGroups={refetchGroups}
onClose={() => setCurrentModal(null)}
onClose={() => {
onClose()
setCurrentModal(null)
}}
/>
)}
</>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/RoleList/ContextMenu/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ const ContextMenu = ({ role, anchorRef, refetchRoles, onClose }) => {
<CurrentModal
role={role}
refetchRoles={refetchRoles}
onClose={() => setCurrentModal(null)}
onClose={() => {
onClose()
setCurrentModal(null)
}}
/>
)}
</>
Expand Down
12 changes: 9 additions & 3 deletions src/pages/UserList/ContextMenu/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ const ContextMenu = ({
userCredentials: { disabled, twoFA },
} = user
const canReplicate =
access.update && currentUser.authorities.has('F_REPLICATE_USER')
access.update &&
(currentUser.authorities.has('ALL') ||
currentUser.authorities.has('F_REPLICATE_USER'))
const canResetPassword =
emailConfigured &&
user.email &&
access.update &&
(currentUser.authorities.has('F_USER_ADD') ||
(currentUser.authorities.has('ALL') ||
currentUser.authorities.has('F_USER_ADD') ||
currentUser.authorities.has('F_USER_ADD_WITHIN_MANAGED_GROUP'))
const canDisable = currentUser.id !== user.id && access.update && !disabled
const canDelete = currentUser.id !== user.id && access.delete
Expand Down Expand Up @@ -152,7 +155,10 @@ const ContextMenu = ({
<CurrentModal
user={user}
refetchUsers={refetchUsers}
onClose={() => setCurrentModal(null)}
onClose={() => {
onClose()
setCurrentModal(null)
}}
/>
)}
</>
Expand Down
8 changes: 2 additions & 6 deletions src/pages/UserList/ContextMenu/Modals/ResetPasswordModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@ const ResetPasswordModal = ({ user, onClose }) => {

return (
<Modal small>
<ModalTitle>
{i18n.t('Reset password of user {{- name}}', {
name: user.displayName,
})}
</ModalTitle>
<ModalTitle>{i18n.t('Reset password')}</ModalTitle>
<ModalContent>
{i18n.t(
`Are you sure you want to reset {{- name}}'s password?`,
`Are you sure you want to reset the password for {{- name}}?`,
{ name: user.displayName }
)}
</ModalContent>
Expand Down
6 changes: 4 additions & 2 deletions src/pages/UserList/UserTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const UserTable = ({
{i18n.t('Last login')}
</DataTableColumnHeader>
<DataTableColumnHeader>
{i18n.t('Account disabled?')}
{i18n.t('Status')}
</DataTableColumnHeader>
<DataTableColumnHeader>
{i18n.t('Actions')}
Expand Down Expand Up @@ -109,7 +109,9 @@ const UserTable = ({
)}
</DataTableCell>
<DataTableCell onClick={handleClick}>
{disabled && i18n.t('Disabled')}
{disabled
? i18n.t('Disabled')
: i18n.t('Active')}
</DataTableCell>
<DataTableCell>
<ContextMenuButton
Expand Down
2 changes: 1 addition & 1 deletion src/pages/UserList/UserTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('<UserTable>', () => {
screen.getByRole('columnheader', { name: 'Last login' })
).toBeInTheDocument()
expect(
screen.getByRole('columnheader', { name: 'Account disabled?' })
screen.getByRole('columnheader', { name: 'Status' })
).toBeInTheDocument()
expect(
screen.getByRole('columnheader', { name: 'Actions' })
Expand Down

0 comments on commit 017a876

Please sign in to comment.