Skip to content

Commit 6516f1c

Browse files
committed
frontend: add confirmation dialog when deselecting include comment in user entity addition
1 parent 14cf648 commit 6516f1c

File tree

3 files changed

+56
-20
lines changed

3 files changed

+56
-20
lines changed

frontend/app.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@
1212
</NuxtLayout>
1313

1414
<Toast />
15+
16+
<ConfirmPopup group="delete">
17+
<template #message="slotProps">
18+
<div class="flex flex-row items-center w-full gap-2 p-4 mb-2 pb-0">
19+
<AppIcon :icon-name="slotProps.message.icon!" />
20+
<span>{{ slotProps.message.message }} <b>{{ (slotProps.message as ExtendedConfirmationOptions).objectId }}</b></span>
21+
</div>
22+
</template>
23+
</ConfirmPopup>
1524
</template>
1625

1726
<script setup lang="ts">
27+
import type { ConfirmationOptions } from 'primevue/confirmationoptions'
1828
import { useHead } from '#imports'
1929
import state from '~/lib/viewer-state'
2030
@@ -28,4 +38,8 @@ useHead({
2838
href: state.logo ?? '/default_favicon.ico',
2939
}],
3040
})
41+
42+
interface ExtendedConfirmationOptions extends ConfirmationOptions {
43+
objectId?: string
44+
}
3145
</script>

frontend/components/viewer/EntityAddForm.vue

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
closable
66
class="w-full max-w-[30rem]"
77
:header="props.family.entity_form.title"
8-
:content-props="{ onClick: (event: Event) => { event.stopPropagation() } }"
98
>
109
<!-- Entity Form Pages -->
1110
<form
@@ -35,12 +34,20 @@
3534
v-model:locations="editedEntity!.locations"
3635
/>
3736

38-
<AdminInputSwitchField
37+
<div
3938
v-if="state.permissions?.can_add_comment"
40-
id="include_comment"
41-
label="Ajouter un commentaire"
42-
v-model:="include_comment"
43-
/>
39+
class="flex flex-col gap-2"
40+
>
41+
<span class="flex items-center gap-2">
42+
<ToggleSwitch
43+
class="shrink-0"
44+
:model-value="include_comment"
45+
input-id="include_comment"
46+
@change="(event: Event) => onIncludeCommentToggle(event)"
47+
/>
48+
<label for="include_comment">Inclure un commentaire</label>
49+
</span>
50+
</div>
4451
</template>
4552
<template v-else>
4653
<FormDynamicField
@@ -147,6 +154,7 @@
147154
</template>
148155

149156
<script setup lang="ts">
157+
import type { ConfirmationOptions } from 'primevue/confirmationoptions'
150158
import type { Category, EntityOrCommentData, Family, FormField, PublicNewComment, PublicNewEntity } from '~/lib'
151159
import state from '~/lib/viewer-state'
152160
import { isValidRichText, isValidText } from '~/lib/validation'
@@ -328,4 +336,32 @@ async function realOnSave(token: string | null) {
328336
}
329337
processingRequest.value = false
330338
}
339+
340+
const confirm = useConfirm()
341+
function onIncludeCommentToggle(event: Event) {
342+
console.log(event)
343+
console.log(event.currentTarget as HTMLElement)
344+
if (!include_comment.value) {
345+
include_comment.value = true
346+
}
347+
else {
348+
const options: ConfirmationOptions = {
349+
target: event.currentTarget as HTMLElement,
350+
group: 'delete',
351+
message: `Ne pas inclure de commentaire empêchera les autres utilisateur·ices de bénéficier de vos retours,
352+
et ne vous laissera préciser que les informations générales. Si vous avez une expérience personelle avec cette entité,
353+
nous vous conseillons d'inclure un commentaire.`,
354+
icon: 'warning',
355+
rejectClass: 'p-button-secondary p-button-outlined p-button-sm',
356+
acceptClass: 'p-button-sm',
357+
rejectLabel: 'Annuler',
358+
acceptLabel: 'Confirmer',
359+
reject: () => {},
360+
accept: () => {
361+
include_comment.value = false
362+
},
363+
}
364+
confirm.require(options)
365+
}
366+
}
331367
</script>

frontend/layouts/admin-ui.vue

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,10 @@
7979
</Card>
8080
</div>
8181
</div>
82-
83-
<ConfirmPopup group="delete">
84-
<template #message="slotProps">
85-
<div class="flex flex-row items-center w-full gap-2 p-4 mb-2 pb-0">
86-
<AppIcon :icon-name="slotProps.message.icon!" />
87-
<span>{{ slotProps.message.message }} <b>{{ (slotProps.message as ExtendedConfirmationOptions).objectId }}</b></span>
88-
</div>
89-
</template>
90-
</ConfirmPopup>
9182
</div>
9283
</template>
9384

9485
<script setup lang="ts">
95-
import type { ConfirmationOptions } from 'primevue/confirmationoptions'
9686
import AdminNavbar from '~/components/admin/Navbar.vue'
9787
9888
type BreadcrumbItem = {
@@ -114,10 +104,6 @@ export type InitAdminLayout = (
114104
breadcrumb: BreadcrumbItem[]
115105
) => void
116106
117-
interface ExtendedConfirmationOptions extends ConfirmationOptions {
118-
objectId?: string
119-
}
120-
121107
const currentBreadcrumbs = ref<BreadcrumbItem[]>([])
122108
const currentActions = ref<ActionItem[]>([])
123109
const cardTitle = ref('')

0 commit comments

Comments
 (0)