Skip to content

Commit fbddcd3

Browse files
feat: handle transfer request notification (#846)
1 parent b1405bb commit fbddcd3

File tree

8 files changed

+135
-33
lines changed

8 files changed

+135
-33
lines changed

components/Notifications/NotificationsList.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
>
77
<NotificationsMembershipRequest
88
v-if="notification.details.class === 'MembershipRequestNotificationDetails'"
9-
:notification
9+
:notification="notification as MembershipRequestNotification"
10+
/>
11+
<NotificationsTransferRequest
12+
v-if="notification.details.class === 'TransferRequestNotificationDetails'"
13+
:notification="notification as TransferRequestNotification"
1014
/>
1115
</div>
1216
</div>
1317
</template>
1418

1519
<script setup lang="ts">
1620
import type { DeepReadonly } from 'vue'
17-
import type { UserNotification } from '~/types/notifications'
21+
import type { MembershipRequestNotification, TransferRequestNotification, UserNotification } from '~/types/notifications'
1822
1923
defineProps<{
2024
notifications: DeepReadonly<Array<UserNotification>>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<template>
2+
<div class="p-3 flex gap-3 relative hover:bg-gray-some">
3+
<div class="flex-none">
4+
<RiSendPlaneLine class="size-4" />
5+
</div>
6+
<div class="flex-1">
7+
<p class="m-0 text-xs font-bold">
8+
<NuxtLink
9+
class="after:absolute after:inset-0 bg-none"
10+
:to="details.link"
11+
>
12+
{{ $t(`Demande de transfert`) }}
13+
</NuxtLink>
14+
</p>
15+
<p class="m-0 text-xs">
16+
{{ $t('de {source}', { source: details.sourceName }) }}
17+
</p>
18+
<p class="m-0 text-xs">
19+
{{ $t('à {recipient}', { recipient: details.recipientName }) }}
20+
</p>
21+
</div>
22+
<div class="flex-none flex m-0 gap-1.5">
23+
<p class="m-0 text-xs">
24+
{{ formatDate(notification.created_at) }}
25+
</p>
26+
<div
27+
v-if="!notification.handled_at"
28+
class="size-2 rounded-full bg-danger mt-0.5"
29+
/>
30+
</div>
31+
</div>
32+
</template>
33+
34+
<script setup lang="ts">
35+
import { useFormatDate } from '@datagouv/components-next'
36+
import { RiSendPlaneLine } from '@remixicon/vue'
37+
import type { DeepReadonly } from 'vue'
38+
import type { TransferRequestNotification } from '~/types/notifications'
39+
40+
const props = defineProps<{
41+
notification: DeepReadonly<TransferRequestNotification>
42+
}>()
43+
44+
const user = useMe()
45+
46+
const details = computed(() => {
47+
const recipient = props.notification.details.transfer_recipient
48+
const source = props.notification.details.transfer_owner
49+
const sourceName = 'first_name' in source ? `${source.first_name} ${source.last_name}` : source.name
50+
const subject = props.notification.details.transfer_subject
51+
const subjectPath = `${subject.class.toLowerCase()}s`
52+
if ('first_name' in recipient) {
53+
return {
54+
link: user.value.id === recipient.id ? `/admin/me/${subjectPath}` : `/admin/users/${recipient.id}/${subjectPath}`,
55+
recipientName: `${recipient.first_name} ${recipient.last_name}`,
56+
sourceName,
57+
}
58+
}
59+
return {
60+
link: `/admin/organizations/${recipient.id}/${subjectPath}`,
61+
recipientName: recipient.name,
62+
sourceName,
63+
}
64+
})
65+
66+
const { formatDate } = useFormatDate()
67+
</script>

datagouv-components/src/main.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import type { Activity, ActivityKey } from './types/activity.js'
33
import type { PaginatedArray } from './types/api.js'
44
import type { ContactPoint, ContactPointRole } from './types/contact_point.js'
55
import type { Badge, Badges, TranslatedBadge } from './types/badges'
6-
import type { Dataset, DatasetV2, DatasetV2WithFullObject, NewDataset, Quality, Rel } from './types/datasets'
7-
import type { NewDataservice, Dataservice } from './types/dataservices'
6+
import type { DatasetReference, Dataset, DatasetV2, DatasetV2WithFullObject, NewDataset, Quality, Rel } from './types/datasets'
7+
import type { DataserviceReference, NewDataservice, Dataservice } from './types/dataservices'
88
import type { AccessType, AccessAudience, AccessAudienceCondition, AccessAudienceType, WithAccessType, AccessTypeForm } from './types/access_types'
99
import type { Frequency, Frequencies } from './types/frequency'
1010
import type { Granularity, Granularities, SpatialZone } from './types/granularity'
1111
import type { Harvest } from './types/harvest'
1212
import type { License } from './types/licenses'
1313
import type { Member, MemberRole, NewOrganization, Organization, OrganizationOrSuggest, OrganizationReference, OrganizationSuggest } from './types/organizations'
1414
import type { Owned, OwnedWithId } from './types/owned'
15-
import type { NewReuse, Reuse, ReuseTopic, ReuseType } from './types/reuses'
15+
import type { ReuseReference, NewReuse, Reuse, ReuseTopic, ReuseType } from './types/reuses'
1616
import type { RegisteredSchema, Schema, SchemaDetails, SchemaField, SchemaPath, SchemaPublicationMode, SchemaResponseData, SchemaVersion, ValidataError } from './types/schemas'
1717
import type { TopicV2, TopicElement, TopicElementClass, TopicElementRel } from './types/topics'
1818
import type { CommunityResource, FileResourceFileType, RemoteResourceFileType, ResourceFileType, ResourceType, Resource } from './types/resources'
@@ -111,9 +111,11 @@ export type {
111111
CommunityResource,
112112
ContactPoint,
113113
ContactPointRole,
114+
DatasetReference,
114115
Dataset,
115116
DatasetV2,
116117
DatasetV2WithFullObject,
118+
DataserviceReference,
117119
Dataservice,
118120
NewDataservice,
119121
FileResourceFileType,
@@ -145,6 +147,7 @@ export type {
145147
Resource,
146148
ResourceFileType,
147149
ResourceType,
150+
ReuseReference,
148151
Reuse,
149152
ReuseTopic,
150153
ReuseType,

datagouv-components/src/types/dataservices.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@ import type { Harvest } from './harvest'
22
import type { Owned, OwnedWithId } from './owned'
33
import type { ContactPoint } from './contact_point'
44
import type { WithAccessType } from './access_types'
5+
import type { DatasetReference } from './datasets'
6+
7+
export type DataserviceReference = {
8+
class: 'Dataservice'
9+
id: string
10+
title: string
11+
self_api_url: string
12+
self_web_url: string
13+
}
514

615
export type BaseDataservice = Owned & WithAccessType & {
716
acronym: string
817
availability: number | null
918
base_api_url: string | null
10-
datasets: Array<{
11-
class: string
12-
id: string
13-
acronym: string
14-
page: string
15-
title: string
16-
uri: string
17-
}>
19+
datasets: Array<DatasetReference>
1820
description: string
1921
machine_documentation_url: string | null
2022
technical_documentation_url: string | null
2123
business_documentation_url: string | null
2224
license: string | null
2325
private: boolean
2426
rate_limiting: string
25-
title: string
27+
title: DataserviceReference['title']
2628
contact_points: Array<ContactPoint>
2729
}
2830

@@ -50,7 +52,7 @@ export type Dataservice = Owned & WithAccessType & {
5052
extras: Record<string, unknown>
5153
format: string
5254
harvest: Harvest
53-
id: string
55+
id: DataserviceReference['id']
5456
license: string | null
5557
metadata_modified_at: string
5658
metrics: {
@@ -63,8 +65,8 @@ export type Dataservice = Owned & WithAccessType & {
6365
permissions: { edit: boolean, delete: boolean }
6466
private: boolean
6567
rate_limiting: string
66-
self_api_url: string
67-
self_web_url: string
68+
self_api_url: DataserviceReference['self_api_url']
69+
self_web_url: DataserviceReference['self_web_url']
6870
slug: string
6971
tags: Array<string>
7072
title: string

datagouv-components/src/types/datasets.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@ export type Quality = {
2323
update_fulfilled_in_time: boolean
2424
}
2525

26-
export type BaseDataset = Owned & WithAccessType & {
27-
title: string
26+
export type DatasetReference = {
27+
class: 'Dataset'
28+
id: string
2829
acronym: string
30+
page: string
31+
title: string
32+
uri: string
33+
}
34+
35+
export type BaseDataset = Owned & WithAccessType & {
36+
title: DatasetReference['title']
37+
acronym: DatasetReference['acronym']
2938
archived: boolean
3039
description: string
3140
description_short: string
@@ -58,10 +67,10 @@ export type Rel = {
5867
}
5968

6069
export type Dataset = BaseDataset & {
61-
id: string
70+
id: DatasetReference['id']
6271
badges: Badges
6372
deleted: string | null
64-
page: string
73+
page: DatasetReference['page']
6574
resources: Array<Resource>
6675
community_resources: Array<Resource>
6776
created_at: string
@@ -71,7 +80,7 @@ export type Dataset = BaseDataset & {
7180
created_at_internal: string
7281
last_modified_internal: string
7382
}
74-
uri: string
83+
uri: DatasetReference['uri']
7584
slug: string
7685
quality: Quality
7786
metrics: {

datagouv-components/src/types/reuses.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@ import type { Dataset } from './datasets'
33
import type { Badges } from './badges'
44
import type { Dataservice } from './dataservices'
55

6-
export type BaseReuse = Owned & {
6+
export type ReuseReference = {
7+
class: 'Reuse'
8+
id: string
79
title: string
10+
image: string | null
11+
uri: string
12+
page: string
13+
}
14+
15+
export type BaseReuse = Owned & {
16+
title: ReuseReference['title']
817
description: string
918
tags: Array<string> | null
1019
datasets: Array<Dataset | string>
@@ -25,8 +34,8 @@ export type Reuse = BaseReuse & {
2534
deleted: string | null
2635
extras: Record<string, unknown>
2736
featured: boolean
28-
id: string
29-
image: string | null
37+
id: ReuseReference['id']
38+
image: ReuseReference['image']
3039
image_thumbnail: string | null
3140
last_modified: string
3241
metrics: {
@@ -37,8 +46,8 @@ export type Reuse = BaseReuse & {
3746
views: number
3847
}
3948
slug: string
40-
page: string
41-
uri: string
49+
page: ReuseReference['page']
50+
uri: ReuseReference['uri']
4251
permissions: { edit: boolean, delete: boolean }
4352
}
4453

types/notifications.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
import type { Organization, User } from '@datagouv/components-next'
1+
import type { DataserviceReference, DatasetReference, OrganizationReference, ReuseReference, UserReference } from '@datagouv/components-next'
22

33
export type CommonNotification = {
44
created_at: string
55
handled_at: string | null
66
id: string
77
last_modified: string
8-
user: User
8+
user: UserReference
99
}
1010

1111
export type MembershipRequestNotification = CommonNotification & {
1212
details: {
1313
class: 'MembershipRequestNotificationDetails'
14-
request_organization: Organization
15-
request_user: User
14+
request_organization: OrganizationReference
15+
request_user: UserReference
1616
}
1717
}
1818

19-
export type UserNotification = MembershipRequestNotification
19+
export type TransferRequestNotification = CommonNotification & {
20+
details: {
21+
class: 'TransferRequestNotificationDetails'
22+
transfer_owner: OrganizationReference | UserReference
23+
transfer_recipient: OrganizationReference | UserReference
24+
transfer_subject: DatasetReference | DataserviceReference | ReuseReference
25+
}
26+
}
27+
28+
export type UserNotification = MembershipRequestNotification | TransferRequestNotification

types/types.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export type MultiSelectOption = {
102102

103103
export type UserSuggest = Omit<User, 'avatar' | 'avatar_thumbnail' | 'roles' | 'pages'> & { avatar_url: string | null }
104104
export type DatasetSuggest = Pick<Dataset, 'acronym' | 'id' | 'slug' | 'title' | 'page'> & { image_url: string | null }
105-
export type DatasetReference = Dataservice['datasets'][0]
106105
export type SpatialZone = {
107106
code: string
108107
id: string

0 commit comments

Comments
 (0)