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

Allow RCL to send Committee notifications #3168

Merged
merged 1 commit into from
Dec 20, 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: 12 additions & 3 deletions cypress/fixtures/news/news.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"notification": true,
"published": true,
"created_at": "2020-10-15T12:00:00+02:00",
"creator": "M Creator 1",
"author": {
"first_name": "M",
"last_name": "Creator 1"
},
"pinned": false
},
{
Expand All @@ -36,7 +39,10 @@
"notification": false,
"published": true,
"created_at": "2020-10-10T12:00:00+02:00",
"creator": "M Creator 2",
"author": {
"first_name": "M",
"last_name": "Creator 2"
},
"pinned": false
},
{
Expand All @@ -55,7 +61,10 @@
"notification": false,
"published": true,
"created_at": "2020-10-10T12:00:00+02:00",
"creator": "M Creator 2",
"author": {
"first_name": "M",
"last_name": "Creator 2"
},
"pinned": true
}
]
Expand Down
7 changes: 2 additions & 5 deletions src/api/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getNewsQuery = async ({ pageParam: page = 1 }) => {
n.text,
n.external_link,
n.link_label,
n.creator,
n.author,
parseDate(n.created_at),
n.notification,
n.published,
Expand All @@ -31,17 +31,13 @@ export const getNewsQuery = async ({ pageParam: page = 1 }) => {

export const updateNewsQuery = news =>
apiClient.put(`api/v3/jecoute/news/${news.id}`, {
uuid: news.id,
title: news.title,
text: news.body,
created_at: news.createdAt,
external_link: news.url,
link_label: news.urlLabel,
creator: news.creator,
notification: news.withNotification,
published: news.status,
pinned: news.pinned,
zone: news.zoneId,
enriched: true,
})

Expand All @@ -61,4 +57,5 @@ export const createNewsQuery = news =>
published: true,
zone: news.zoneId,
enriched: true,
committee: news.committeeUuid,
})
4 changes: 2 additions & 2 deletions src/components/News/CreateEditModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { SubTitle, Title } from './styles'
import Button from '~/ui/Button'
import Dialog from '~/ui/Dialog'
import { EDITOR_IMAGE_UPLOAD_URL } from './constants'
import scopes from '~/shared/scopes'

const newsSchema = Yup.object({
title: Yup.string().min(1, 'Minimum 1 caractère').max(120, 'Maximum 120 caractères').required('Titre obligatoire'),
Expand Down Expand Up @@ -95,7 +94,8 @@ const CreateEditModal = ({ open, news, onCloseResolve, onSubmitResolve }) => {
.withUrlLabel(values.urlLabel)
.withWithNotification(values.withNotification)
.withStatus(values.status)
.withZoneId(currentScope.code === scopes.national ? null : currentScope.zones[0].uuid)
.withZoneId(currentScope.zones.length ? currentScope.zones[0].uuid : null)
.withCommitteeUuid(currentScope.getCommittees()[0]?.uuid ?? null)
)
},
})
Expand Down
7 changes: 6 additions & 1 deletion src/components/News/NewsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ const NewsList = ({ data, toggleNewsStatus, toggleNewsPinned, handleEdit, handle
header={
<>
<Header {...n} />
<Title subject={n.title} author={n.creator} sx={{ pt: 1 }} dateTime={n.createdAt} />
<Title
subject={n.title}
author={`${n.creator.first_name} ${n.creator.last_name}`}
sx={{ pt: 1 }}
dateTime={n.createdAt}
/>
</>
}
actionsProps={{ sx: { pt: 3 } }}
Expand Down
2 changes: 1 addition & 1 deletion src/components/News/ReadModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const ReadModal = ({ open, news, handleEdit, onCloseResolve }) => {
<Title title={news?.title}>{news?.title}</Title>
<UserTimeContainer>
<PersonIcon sx={{ mr: 0.5, color: 'gray600', fontSize: '12px' }} />
<Author>{news?.creator}</Author>
<Author>{`${news?.creator?.first_name} ${news?.creator?.last_name}`}</Author>
<AccessTimeIcon sx={{ mr: 0.5, ml: 2, color: 'gray600', fontSize: '12px' }} />
<DateItem>
{news?.createdAt && `Le ${formatDate(news.createdAt, 'dd/MM/yyyy')} à ${formatDate(news.createdAt, 'HH:mm')}`}
Expand Down
70 changes: 48 additions & 22 deletions src/domain/news.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import PropTypes from 'prop-types'

export default class News {
constructor(id, title, body, url, urlLabel, creator, createdAt, withNotification, status, pinned, zoneId) {
constructor(
id,
title,
body,
url,
urlLabel,
creator,
createdAt,
withNotification,
status,
pinned,
zoneId,
committeeUuid
) {
this.id = id
this.title = title
this.body = body
Expand All @@ -12,9 +26,10 @@ export default class News {
this.status = status
this.pinned = pinned
this.zoneId = zoneId
this.committeeUuid = committeeUuid
}

static NULL = new News(null, '', '', '', '', '', new Date(), false, false, false, '')
static NULL = new News(null, '', '', '', '', null, new Date(), false, false, false, '', null)

withTitle(newTitle) {
return new News(
Expand All @@ -28,7 +43,8 @@ export default class News {
this.withNotification,
this.status,
this.pinned,
this.zoneId
this.zoneId,
this.committeeUuid
)
}

Expand All @@ -44,7 +60,8 @@ export default class News {
this.withNotification,
this.status,
this.pinned,
this.zoneId
this.zoneId,
this.committeeUuid
)
}

Expand All @@ -60,7 +77,8 @@ export default class News {
this.withNotification,
this.status,
this.pinned,
this.zoneId
this.zoneId,
this.committeeUuid
)
}

Expand All @@ -76,7 +94,8 @@ export default class News {
this.withNotification,
this.status,
this.pinned,
this.zoneId
this.zoneId,
this.committeeUuid
)
}

Expand All @@ -92,7 +111,8 @@ export default class News {
newWithNotification,
this.status,
this.pinned,
this.zoneId
this.zoneId,
this.committeeUuid
)
}

Expand All @@ -108,11 +128,12 @@ export default class News {
this.withNotification,
newStatus,
this.pinned,
this.zoneId
this.zoneId,
this.committeeUuid
)
}

withPinned(newPinned) {
toggleStatus() {
return new News(
this.id,
this.title,
Expand All @@ -122,13 +143,14 @@ export default class News {
this.creator,
this.createdAt,
this.withNotification,
this.status,
newPinned,
this.zoneId
!this.status,
this.pinned,
this.zoneId,
this.committeeUuid
)
}

toggleStatus() {
togglePinned() {
return new News(
this.id,
this.title,
Expand All @@ -138,13 +160,14 @@ export default class News {
this.creator,
this.createdAt,
this.withNotification,
!this.status,
this.pinned,
this.zoneId
this.status,
!this.pinned,
this.zoneId,
this.committeeUuid
)
}

togglePinned() {
withZoneId(newZoneId) {
return new News(
this.id,
this.title,
Expand All @@ -155,12 +178,13 @@ export default class News {
this.createdAt,
this.withNotification,
this.status,
!this.pinned,
this.zoneId
this.pinned,
newZoneId,
this.committeeUuid
)
}

withZoneId(newZoneId) {
withCommitteeUuid(committeeUuid) {
return new News(
this.id,
this.title,
Expand All @@ -172,7 +196,8 @@ export default class News {
this.withNotification,
this.status,
this.pinned,
newZoneId
this.zoneId,
committeeUuid
)
}
}
Expand All @@ -183,10 +208,11 @@ News.propTypes = PropTypes.shape({
body: PropTypes.string.isRequired,
url: PropTypes.string,
urlLabel: PropTypes.string,
creator: PropTypes.string,
creator: PropTypes.object,
createdAt: PropTypes.object.isRequired,
withNotification: PropTypes.bool,
status: PropTypes.bool.isRequired,
pinned: PropTypes.bool.isRequired,
zoneId: PropTypes.string,
committeeUuid: PropTypes.string,
})
Loading