Skip to content

Commit 39d6227

Browse files
committed
fix notifications
1 parent c930b8b commit 39d6227

5 files changed

Lines changed: 169 additions & 127 deletions

File tree

src/components/specific/projects/project-notification-card/ProjectNotificationCard.vue

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
class="m-t-12"
2424
@click="$emit('open-recipients-settings')"
2525
>
26-
{{
27-
$t("ProjectOverview.notifications.settings.activity.recipientsNotificationsButton")
28-
}}
26+
{{ $t("ProjectOverview.notifications.settings.activity.recipientsNotificationsButton") }}
2927
({{ selectedRecipientsIds.length }})
3028
</BIMDataButton>
31-
<div v-for="(options, section) in activityOptions" :key="section">
29+
30+
<div v-for="(labels, section) in activityOptions" :key="section">
3231
<h5>{{ section }}</h5>
3332
<BIMDataCheckbox
34-
v-for="label in options"
35-
:key="label"
33+
v-for="(label, index) in labels"
34+
:key="`${section}-${index}`"
3635
:text="label"
37-
v-model="modelActivity[label]"
36+
v-model="modelActivity[getActivityKey(section, index)]"
3837
margin="6px 0"
3938
/>
4039
</div>
40+
4141
<div class="separator"></div>
4242
</div>
4343

@@ -61,15 +61,16 @@
6161

6262
<!-- Days -->
6363
<BIMDataCheckbox
64-
v-for="[day, isChecked] in Object.entries(modelDays)"
65-
:key="`${type}-${day}`"
66-
:text="day"
67-
v-model="modelDays[day]"
64+
v-for="(label, key) in daysLabels"
65+
:key="`${type}-${key}`"
66+
:text="label"
67+
v-model="modelDays[key]"
6868
margin="6px 0 6px 23px"
6969
/>
70+
7071
<div class="flex items-center m-l-24 m-t-12">
7172
<span>À :</span>
72-
<TimePicker v-model="selectedTime" class="m-x-12" />
73+
<TimePicker v-model="notificationTime" class="m-x-12" />
7374
<BIMDataButton
7475
color="primary"
7576
outline
@@ -79,7 +80,7 @@
7980
style="flex:1;"
8081
class="justify-between"
8182
>
82-
{{ selectedTimezone || "Timezone" }}
83+
{{ currentTimezone }}
8384
<BIMDataIconChevron size="xxs" fill color="default" />
8485
</BIMDataButton>
8586
</div>
@@ -90,15 +91,16 @@
9091
</template>
9192

9293
<script setup>
93-
import { ref, defineModel, watch } from "vue";
94+
import { ref, defineModel, computed, watch } from "vue";
9495
import { useI18n } from "vue-i18n";
95-
9696
import { useNotificationSchedule } from "../../../../state/notifications.js";
97-
97+
import {
98+
getActivityOptions,
99+
getDaysLabels,
100+
RAW_ACTIVITY_OPTIONS,
101+
} from "../../../../utils/notifications.js";
98102
import TimePicker from "../../../generic/time-picker/TimePicker.vue";
99103
100-
const { t } = useI18n();
101-
102104
const props = defineProps({
103105
title: String,
104106
type: String,
@@ -107,23 +109,47 @@ const props = defineProps({
107109
type: Array,
108110
default: () => [],
109111
},
112+
notification: {
113+
type: Object,
114+
default: () => ({}),
115+
},
110116
});
111117
112118
const emit = defineEmits([
113119
"update:notification-mode-value",
114120
"update:model-days",
115121
"update:model-activity",
122+
"update:selected-time",
116123
"open-recipients-settings",
117124
"open-timezone-choice",
118125
]);
119126
120127
const open = ref(props.defaultOpen);
121128
const toggle = () => (open.value = !open.value);
122129
123-
const { selectedTime, selectedTimezone } = useNotificationSchedule();
130+
const { t } = useI18n();
131+
const { selectedTimezone } = useNotificationSchedule();
132+
124133
const notificationModeValue = defineModel("notificationModeValue");
125134
const modelDays = defineModel("modelDays");
126135
const modelActivity = defineModel("modelActivity");
136+
const selectedTime = defineModel("selectedTime");
137+
138+
const daysLabels = computed(() => getDaysLabels(t));
139+
const activityOptions = computed(() => getActivityOptions(t));
140+
141+
const getActivityKey = (section, index) => RAW_ACTIVITY_OPTIONS[section][index];
142+
143+
const notificationTime = computed({
144+
get: () => selectedTime.value,
145+
set: (val) => {
146+
selectedTime.value = val;
147+
},
148+
});
149+
150+
const currentTimezone = computed(() =>
151+
props.notification?.schedule?.timezone || selectedTimezone.value || "Timezone"
152+
);
127153
128154
watch(
129155
modelDays,
@@ -135,38 +161,14 @@ watch(
135161
},
136162
{ deep: true }
137163
);
164+
138165
watch(notificationModeValue, (newValue) => {
139166
if (newValue !== "scheduled") {
140167
Object.keys(modelDays.value).forEach((day) => {
141168
modelDays.value[day] = false;
142169
});
143170
}
144171
});
145-
const activityOptions = {
146-
GED: [
147-
t("ProjectOverview.notifications.settings.activity.ged.fileUpload"),
148-
t("ProjectOverview.notifications.settings.activity.ged.fileDeletion"),
149-
// t("ProjectOverview.notifications.settings.activity.ged.newVersion"),
150-
t("ProjectOverview.notifications.settings.activity.ged.folderCreation"),
151-
t("ProjectOverview.notifications.settings.activity.ged.folderDeletion"),
152-
],
153-
Visa: [
154-
t("ProjectOverview.notifications.settings.activity.visa.visaCreation"),
155-
t("ProjectOverview.notifications.settings.activity.visa.visaDeletion"),
156-
t("ProjectOverview.notifications.settings.activity.visa.visaValidation"),
157-
t("ProjectOverview.notifications.settings.activity.visa.visaRejection"),
158-
],
159-
BCF: [
160-
t("ProjectOverview.notifications.settings.activity.bcf.bcfCreation"),
161-
t("ProjectOverview.notifications.settings.activity.bcf.bcfDeletion"),
162-
],
163-
"Autres évènements": [
164-
t("ProjectOverview.notifications.settings.activity.otherEvents.acceptInvit"),
165-
// t("ProjectOverview.notifications.settings.activity.otherEvents.removeModels"),
166-
t("ProjectOverview.notifications.settings.activity.otherEvents.createMetaBuilding"),
167-
t("ProjectOverview.notifications.settings.activity.otherEvents.deleteMetaBuilding"),
168-
],
169-
};
170172
</script>
171173
172174
<style scoped src="./ProjectNotificationCard.css"></style>

src/components/specific/projects/project-notifications-recipients/ProjectNotificationsRecipients.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</template>
4040

4141
<script setup>
42-
import { ref } from "vue";
42+
import { ref, watch } from "vue";
4343
import { useGroups } from "../../../../state/groups.js";
4444
import GroupCard from "./group-card/GroupCard.vue";
4545
@@ -69,6 +69,14 @@ const updateNotifications = () => {
6969
emit("update-recipients", selectedGroupIds.value);
7070
emit("back-to-settings");
7171
};
72+
73+
watch(
74+
() => props.selectedRecipientsIds,
75+
(newVal) => {
76+
selectedGroupIds.value = [...newVal];
77+
},
78+
{ immediate: true }
79+
);
7280
</script>
7381

7482
<style scoped src="./ProjectNotificationsRecipients.css"></style>

src/components/specific/projects/project-notifications-settings/ProjectNotificationsSettings.vue

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
<BIMDataIconClose size="xxs" fill color="granite-light" />
1414
</BIMDataButton>
1515
</div>
16+
1617
<div class="header m-t-12">
1718
<p class="text-center">
1819
{{ $t("ProjectOverview.notifications.headerText") }}
1920
</p>
2021
</div>
22+
2123
<div class="m-t-18">
2224
<ProjectNotificationCard
23-
:notification="notifications"
25+
:notification="notification"
2426
:title="$t('ProjectOverview.notifications.settings.activity.title')"
2527
type="activity"
2628
:selectedRecipientsIds="selectedRecipientsIds"
@@ -38,7 +40,7 @@
3840
</ProjectNotificationCard>
3941
</div>
4042

41-
<div class="footer m-t-18">
43+
<div class="footer m-t-6">
4244
<BIMDataButton
4345
color="primary"
4446
fill
@@ -54,7 +56,7 @@
5456
</template>
5557

5658
<script setup>
57-
import { onMounted } from "vue";
59+
import { ref, onMounted } from "vue";
5860
import { useRoute } from "vue-router";
5961
import { useI18n } from "vue-i18n";
6062
@@ -71,6 +73,7 @@ const props = defineProps({
7173
default: () => [],
7274
},
7375
});
76+
7477
const notificationModeActivity = defineModel("notificationModeActivity");
7578
const checkedDaysActivity = defineModel("checkedDaysActivity");
7679
const checkedActivity = defineModel("checkedActivity");
@@ -79,23 +82,37 @@ defineEmits(["open-recipients-settings", "close", "open-timezone-choice"]);
7982
const { t, locale } = useI18n();
8083
const route = useRoute();
8184
const { pushNotification } = useAppNotification();
82-
const {
83-
notifications,
84-
fetchProjectNotification,
85-
updateProjectNotification,
86-
deleteProjectNotification,
87-
} = useProjects();
85+
const { fetchProjectNotification, updateProjectNotification, deleteProjectNotification } =
86+
useProjects();
8887
8988
const spaceID = +route.params.spaceID;
9089
const projectID = +route.params.projectID;
9190
const { selectedTime, selectedTimezone } = useNotificationSchedule();
9291
const activityMapping = getActivityMapping(t);
9392
93+
const defaultDays = {
94+
monday: false,
95+
tuesday: false,
96+
wednesday: false,
97+
thursday: false,
98+
friday: false,
99+
saturday: false,
100+
sunday: false,
101+
};
102+
const notification = ref({});
103+
104+
if (
105+
!checkedDaysActivity.value ||
106+
Object.keys(checkedDaysActivity.value).some((k) => !defaultDays.hasOwnProperty(k))
107+
) {
108+
checkedDaysActivity.value = { ...defaultDays };
109+
}
110+
94111
onMounted(async () => {
95112
try {
96-
const notification = await fetchProjectNotification(spaceID, projectID);
97-
if (notification) {
98-
initializeStateFromNotification(notification);
113+
notification.value = await fetchProjectNotification(spaceID, projectID);
114+
if (notification.value) {
115+
initializeStateFromNotification(notification.value);
99116
}
100117
} catch (error) {
101118
console.log("Pas de notification configurée dans le projet");
@@ -126,13 +143,7 @@ const updateNotifications = async () => {
126143
? {
127144
time: selectedTime.value,
128145
timezone: selectedTimezone.value,
129-
monday: checkedDaysActivity.value["Lundi"],
130-
tuesday: checkedDaysActivity.value["Mardi"],
131-
wednesday: checkedDaysActivity.value["Mercredi"],
132-
thursday: checkedDaysActivity.value["Jeudi"],
133-
friday: checkedDaysActivity.value["Vendredi"],
134-
saturday: checkedDaysActivity.value["Samedi"],
135-
sunday: checkedDaysActivity.value["Dimanche"],
146+
...checkedDaysActivity.value,
136147
}
137148
: null;
138149
@@ -152,17 +163,11 @@ const updateNotifications = async () => {
152163
153164
if (notificationModeActivity.value === "disabled") {
154165
await handleDeleteNotification();
155-
156166
Object.keys(checkedActivity.value).forEach((key) => {
157167
checkedActivity.value[key] = false;
158168
});
159-
160-
Object.keys(checkedDaysActivity.value).forEach((day) => {
161-
checkedDaysActivity.value[day] = false;
162-
});
163-
169+
Object.assign(checkedDaysActivity.value, { ...defaultDays });
164170
props.selectedRecipientsIds.splice(0);
165-
166171
return;
167172
} else {
168173
try {
@@ -193,15 +198,18 @@ const initializeStateFromNotification = (notification) => {
193198
194199
if (notification.schedule) {
195200
Object.assign(checkedDaysActivity.value, {
196-
Lundi: notification.schedule.monday,
197-
Mardi: notification.schedule.tuesday,
198-
Mercredi: notification.schedule.wednesday,
199-
Jeudi: notification.schedule.thursday,
200-
Vendredi: notification.schedule.friday,
201-
Samedi: notification.schedule.saturday,
202-
Dimanche: notification.schedule.sunday,
201+
monday: notification.schedule.monday,
202+
tuesday: notification.schedule.tuesday,
203+
wednesday: notification.schedule.wednesday,
204+
thursday: notification.schedule.thursday,
205+
friday: notification.schedule.friday,
206+
saturday: notification.schedule.saturday,
207+
sunday: notification.schedule.sunday,
203208
});
204209
210+
selectedTime.value = notification.schedule.time;
211+
selectedTimezone.value = notification.schedule.timezone;
212+
205213
notificationModeActivity.value = Object.values(checkedDaysActivity.value).some(Boolean)
206214
? "scheduled"
207215
: "immediate";

0 commit comments

Comments
 (0)