bfg-common 1.4.311 → 1.4.313

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,11 +12,10 @@
12
12
 
13
13
  <Teleport to="body">
14
14
  <common-layout-the-header-user-menu-modals-change-password
15
- v-if="isShowChangePasswordModal"
16
- v-model="isShowChangePasswordModal"
17
- :new-view="props.newView"
15
+ :show="isChangePassword"
18
16
  :hostname="props.hostname"
19
17
  :project="props.project"
18
+ @hide="isChangePassword = false"
20
19
  />
21
20
 
22
21
  <common-layout-the-header-user-menu-modals-preferences
@@ -75,7 +74,7 @@ const emits = defineEmits<{
75
74
 
76
75
  const { $store }: any = useNuxtApp()
77
76
 
78
- const isShowChangePasswordModal = ref<boolean>(false)
77
+ const isChangePassword = ref<boolean>(false)
79
78
 
80
79
  const onLogout = async (): Promise<void> => {
81
80
  await $store.dispatch('auth/A_LOGOUT', null)
@@ -84,7 +83,7 @@ const onLogout = async (): Promise<void> => {
84
83
  const onSelectDropdown = (value: string): void => {
85
84
  switch (value) {
86
85
  case 'changePassword':
87
- isShowChangePasswordModal.value = true
86
+ isChangePassword.value = true
88
87
  break
89
88
  case 'preferences':
90
89
  emits('show-preference')
@@ -1,20 +1,88 @@
1
1
  <template>
2
- <common-layout-the-header-user-menu-modals-change-password-new
3
- v-if="newView"
4
- v-model="form"
5
- :subtitle="props.hostname"
6
- :project="props.project"
2
+ <atoms-modal
3
+ width="580px"
4
+ test-id="change-password"
5
+ :show="props.show"
6
+ :title="localization.common.changePassword"
7
+ :second-title="props.hostname"
8
+ :disabled-submit="buttonDisabled"
7
9
  @hide="onHideModal"
8
- @apply="onChangePassword"
9
- />
10
-
11
- <common-layout-the-header-user-menu-modals-change-password-old
12
- v-else
13
- :hostname="props.hostname"
14
- :project="props.project"
15
- @hide="onHideModal"
16
- @apply="onChangePassword"
17
- />
10
+ @submit="onChangePassword"
11
+ >
12
+ <template #modalBody>
13
+ <form id="change-password-form" class="compact" @submit.prevent>
14
+ <section class="form-block">
15
+ <div class="form-group">
16
+ <label for="current-password-field"
17
+ >{{ localization.common.currentPassword }}:</label
18
+ >
19
+ <input
20
+ id="current-password-field"
21
+ v-model="form.password.value"
22
+ data-id="change-password-input"
23
+ type="password"
24
+ />
25
+ </div>
26
+
27
+ <div class="form-group">
28
+ <label for="new-password-field"
29
+ >{{ localization.common.newPassword }}:</label
30
+ >
31
+
32
+ <div class="form-group__input">
33
+ <atoms-tooltip-error
34
+ :has-error="isValid"
35
+ selector="#new-password-field"
36
+ >
37
+ <template #elem>
38
+ <input
39
+ id="new-password-field"
40
+ v-model="form.newPassword.value"
41
+ data-id="new-password-input"
42
+ type="password"
43
+ />
44
+ </template>
45
+ <template #content>{{ errorText }}</template>
46
+ </atoms-tooltip-error>
47
+ <atoms-the-icon
48
+ v-show="isValid"
49
+ class="is-error tooltip-trigger"
50
+ name="info"
51
+ />
52
+ </div>
53
+ </div>
54
+
55
+ <div class="form-group">
56
+ <label for="confirm-password-field"
57
+ >{{ localization.common.confirmPassword }}:</label
58
+ >
59
+
60
+ <div class="form-group__input">
61
+ <atoms-tooltip-error
62
+ :has-error="isValid"
63
+ selector="#confirm-password-field"
64
+ >
65
+ <template #elem>
66
+ <input
67
+ id="confirm-password-field"
68
+ v-model="form.confirmPassword.value"
69
+ data-id="confirm-password-input"
70
+ type="password"
71
+ />
72
+ </template>
73
+ <template #content>{{ errorText }}</template>
74
+ </atoms-tooltip-error>
75
+ <atoms-the-icon
76
+ v-show="isValid"
77
+ class="is-error tooltip-trigger"
78
+ name="info"
79
+ />
80
+ </div>
81
+ </div>
82
+ </section>
83
+ </form>
84
+ </template>
85
+ </atoms-modal>
18
86
  </template>
19
87
 
20
88
  <script setup lang="ts">
@@ -28,11 +96,13 @@ import type { UI_T_Project } from '~/lib/models/types'
28
96
  import { defaultFormFunc } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/config/form'
29
97
 
30
98
  const props = defineProps<{
31
- newView: boolean
99
+ show: boolean
32
100
  hostname: string
33
101
  project: UI_T_Project
34
102
  }>()
35
- const isShowModalLocal = defineModel<boolean>({ required: true })
103
+ const emits = defineEmits<{
104
+ (event: 'hide'): void
105
+ }>()
36
106
 
37
107
  const localization = computed<UI_I_Localization>(() => useLocal())
38
108
  const { $store, $validation }: any = useNuxtApp()
@@ -50,6 +120,15 @@ const setForm = (): void => {
50
120
  }
51
121
  setForm()
52
122
 
123
+ const buttonDisabled = computed<boolean>(() => {
124
+ const { password, confirmPassword, newPassword } = form.value
125
+ return (
126
+ password.value &&
127
+ confirmPassword.value &&
128
+ newPassword.value !== confirmPassword.value
129
+ )
130
+ })
131
+
53
132
  const onChangePassword = async (): Promise<void> => {
54
133
  const valid = validation.touch()
55
134
  const { newPassword, password } = form.value
@@ -105,8 +184,27 @@ const showValidationErrors = (text: string): void => {
105
184
  }
106
185
 
107
186
  const onHideModal = (): void => {
108
- isShowModalLocal.value = false
187
+ emits('hide')
109
188
  setForm()
110
189
  isValid.value = false
111
190
  }
112
191
  </script>
192
+
193
+ <style lang="scss" scoped>
194
+ .form-block {
195
+ .form-group {
196
+ &:not(:first-child) input {
197
+ width: 100%;
198
+ }
199
+ &__input {
200
+ display: flex;
201
+ width: 100%;
202
+ }
203
+ }
204
+
205
+ svg {
206
+ width: 24px;
207
+ height: 24px;
208
+ }
209
+ }
210
+ </style>
@@ -62,6 +62,8 @@ watch(
62
62
  ([newValue1, newValue2]: [string, 'never' | 'on']) => {
63
63
  modelFrequencyLocal.value.isValid =
64
64
  newValue2 === 'never' ? false : !!newValue1
65
+
66
+ newValue2 === 'never' && (modelFrequencyLocal.value.frg_end_time = '')
65
67
  }
66
68
  )
67
69
  </script>
@@ -62,7 +62,8 @@ const getCorrectRuForm = (value: number | string, type: string): string => {
62
62
  export const validateField = (
63
63
  localization: UI_I_Localization,
64
64
  value: string,
65
- checkZero: boolean = false
65
+ checkZero: boolean = false,
66
+ checkDayRange: boolean = false // параметр для проверки диапазона дней
66
67
  ): string => {
67
68
  // Если поле пустое
68
69
  if (!value) {
@@ -74,7 +75,7 @@ export const validateField = (
74
75
  return localization.common.theValueTooSmall
75
76
  }
76
77
 
77
- if (value.length > 3) {
78
+ if (value.length > 3 ) {
78
79
  return localization.common.theValueTooLarge
79
80
  }
80
81
  // Если значение не является цифрой
@@ -82,6 +83,10 @@ export const validateField = (
82
83
  return localization.common.inputContainsInvalidCharacters
83
84
  }
84
85
 
86
+ if (checkDayRange && !/^([1-9]|[1-2][0-9]|3[0-1])$/.test(value)) {
87
+ return localization.common.theValueTooLarge
88
+ }
89
+
85
90
  return ''
86
91
  }
87
92
  export const validateDate = (
@@ -9,11 +9,11 @@
9
9
  v-model="model"
10
10
  />
11
11
 
12
- <div v-if="props.type === 'month'" class="">
12
+ <div v-if="props.type === 'month'">
13
13
  <div class="on-time__radio radio">
14
14
  <input
15
15
  id="on-time-monthly-by-day"
16
- v-model="selectedTimeMode"
16
+ v-model="model.frg_monthly_mode"
17
17
  data-id="on-time-monthly-by-day"
18
18
  type="radio"
19
19
  value="day"
@@ -49,7 +49,7 @@
49
49
  <div class="on-time__radio radio">
50
50
  <input
51
51
  id="on-time-monthly-by-week"
52
- v-model="selectedTimeMode"
52
+ v-model="model.frg_monthly_mode"
53
53
  data-id="on-time-monthly-by-week"
54
54
  type="radio"
55
55
  value="week"
@@ -115,8 +115,6 @@ const model = defineModel<UI_I_ScheduleNewTasksForm>({ required: true })
115
115
 
116
116
  const localization = computed<UI_I_Localization>(() => useLocal())
117
117
 
118
- const selectedTimeMode = ref<'day' | 'week'>('day')
119
-
120
118
  const frequencyOnWeeksDays = computed<UI_I_SelectInputItem[]>(() => {
121
119
  return frequencyOnWeeksDaysFunc(localization.value)
122
120
  })
@@ -125,7 +123,7 @@ const frequencyOnOrdinalNumber = computed<UI_I_SelectInputItem[]>(() => {
125
123
  })
126
124
 
127
125
  const isDisabledMonthlyDayField = computed<boolean>(
128
- () => selectedTimeMode.value === 'week'
126
+ () => model.value.frg_monthly_mode === 'week'
129
127
  )
130
128
 
131
129
  const isInitTimeIntervalValidation = ref<boolean>(false)
@@ -136,7 +134,12 @@ const schedulerOnDayErrorText = computed<string>(() => {
136
134
  if (!isInitTimeIntervalValidation.value || isDisabledMonthlyDayField.value)
137
135
  return ''
138
136
 
139
- return validateField(localization.value, model.value.frg_monthly_day, true)
137
+ return validateField(
138
+ localization.value,
139
+ model.value.frg_monthly_day,
140
+ true,
141
+ true
142
+ )
140
143
  })
141
144
  watch(
142
145
  schedulerOnDayErrorText,
@@ -7,31 +7,31 @@ export const frequencyOnWeeksDaysFunc = (
7
7
  return [
8
8
  {
9
9
  label: localization.common.sunday,
10
- value: 'sunday',
10
+ value: 6,
11
11
  },
12
12
  {
13
13
  label: localization.common.monday,
14
- value: 'monday',
14
+ value: 1,
15
15
  },
16
16
  {
17
17
  label: localization.common.tuesday,
18
- value: 'tuesday',
18
+ value: 2,
19
19
  },
20
20
  {
21
21
  label: localization.common.wednesday,
22
- value: 'wednesday',
22
+ value: 3,
23
23
  },
24
24
  {
25
25
  label: localization.common.thursday,
26
- value: 'thursday',
26
+ value: 4,
27
27
  },
28
28
  {
29
29
  label: localization.common.friday,
30
- value: 'friday',
30
+ value: 5,
31
31
  },
32
32
  {
33
33
  label: localization.common.saturday,
34
- value: 'saturday',
34
+ value: 0,
35
35
  },
36
36
  ]
37
37
  }
@@ -42,23 +42,23 @@ export const frequencyOnOrdinalNumberFunc = (
42
42
  return [
43
43
  {
44
44
  label: localization.scheduledTasks.first,
45
- value: '',
45
+ value: 1,
46
46
  },
47
47
  {
48
48
  label: localization.scheduledTasks.second,
49
- value: 'once',
49
+ value: 2,
50
50
  },
51
51
  {
52
52
  label: localization.scheduledTasks.third,
53
- value: 'after-startup',
53
+ value: 3,
54
54
  },
55
55
  {
56
56
  label: localization.scheduledTasks.fourth,
57
- value: 'hour',
57
+ value: 4,
58
58
  },
59
59
  {
60
60
  label: localization.common.last,
61
- value: 'day',
61
+ value: 5,
62
62
  },
63
63
  ]
64
64
  }
@@ -101,6 +101,7 @@ import type { UI_I_SelectInputItem } from '~/components/common/select/input/lib/
101
101
  import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
102
102
  import type { UI_I_InitialValidationFields } from '~/components/common/pages/scheduledTasks/modals/common/newTaskForm/lib/models/interfaces'
103
103
  import type { UI_T_FrequencyType } from '~/components/common/pages/scheduledTasks/modals/common/frequency/lib/models/types'
104
+ import * as cron from '~/components/common/pages/scheduledTasks/modals/common/newTaskForm/lib/utils'
104
105
  import { frequencyMethodFunc } from '~/components/common/pages/scheduledTasks/modals/common/frequency/lib/config/frequencyOptions'
105
106
 
106
107
  const props = defineProps<{
@@ -133,57 +134,6 @@ watch(
133
134
  },
134
135
  { deep: true }
135
136
  )
136
- /* TODO рефакторинг все методы надо рефакторить */
137
- const generateOnceCronExpression = (date: Date): any => {
138
- if (!date) return
139
-
140
- const minutes = date.getMinutes()
141
- const hours = date.getHours()
142
- const day = date.getDate()
143
- const month = date.getMonth() + 1 // В cron месяцы начинаются с 1 (январь = 1)
144
- const dayOfWeek = '*' // Для одноразовой задачи день недели неважен
145
-
146
- // Генерируем cron-выражение
147
- return `${minutes} ${hours} ${day} ${month} ${dayOfWeek} once`
148
- }
149
- const generateHourlyCronExpression = (delay: string, date: Date): any => {
150
- if (!date) return
151
-
152
- const minutes = date.getMinutes()
153
- const hours = date.getHours()
154
-
155
- // Генерируем cron-выражение
156
- return `${minutes} ${hours}/${delay} * * *`
157
- }
158
- const generateDaylyCronExpression = (delay: string, date: Date): string => {
159
- if (!date) return
160
-
161
- const minutes = date.getMinutes()
162
- const hours = date.getHours()
163
- const day = date.getDate()
164
-
165
- // Генерируем cron-выражение
166
- return `${minutes} ${hours} ${day}/${delay} * *`
167
- }
168
- const generateWeeklyCronExpression = (
169
- data: UI_I_ScheduleNewTasksForm
170
- ): string => {
171
- const { frg_on_week_days } = data
172
-
173
- // Генерируем cron-выражение
174
- return `* * * * ${frg_on_week_days.join(',')}`
175
- }
176
- const generateMonthlyCronExpression = (delay: string, date: Date): string => {
177
- if (!date) return
178
-
179
- const minutes = date.getMinutes()
180
- const hours = date.getHours()
181
- const day = date.getDate()
182
- const month = date.getMonth() + 1
183
-
184
- // Генерируем cron-выражение
185
- return `${minutes} ${hours} ${day} ${month}/${delay} *`
186
- }
187
137
 
188
138
  const generateCronExpression = (
189
139
  runType: UI_T_FrequencyType,
@@ -194,40 +144,27 @@ const generateCronExpression = (
194
144
  // Генерируем cron-выражение на основе runType
195
145
  switch (runType) {
196
146
  case 'once':
197
- cronExpression = generateOnceCronExpression(
198
- new Date(interval.frg_on_time)
147
+ const timestamp = Math.floor(
148
+ new Date(interval.frg_on_time).getTime() / 1000
199
149
  )
150
+ cronExpression = `* * * * * ${timestamp}:0-0-0-0:once`
200
151
  break
201
152
  case 'after-startup':
202
- const delay =
203
- interval.frg_after_startup === 0
204
- ? '*'
205
- : `*/${interval.frg_after_startup}`
206
- cronExpression = `${delay} * * * * after_procurator_startup` // Выполняется каждые N минут после запуска procurator_startup
153
+ const suffixDelay =
154
+ interval.frg_after_startup === 0 ? '' : `-${interval.frg_after_startup}`
155
+ cronExpression = `* * * * * after_procurator_startup${suffixDelay}` // Выполняется после запуска procurator_startup с задержой N минут
207
156
  break
208
157
  case 'hour':
209
- const hourlyDelay = interval.frg_interval
210
- cronExpression = generateHourlyCronExpression(
211
- hourlyDelay,
212
- new Date(interval.frg_start_on_time)
213
- )
158
+ cronExpression = cron.generateHourlyCronExpression(interval)
214
159
  break
215
160
  case 'day':
216
- const dayDelay = interval.frg_interval
217
- cronExpression = generateDaylyCronExpression(
218
- dayDelay,
219
- new Date(interval.frg_start_on_time)
220
- )
161
+ cronExpression = cron.generateDailyCronExpression(interval)
221
162
  break
222
163
  case 'week':
223
- cronExpression = generateWeeklyCronExpression(interval)
164
+ cronExpression = cron.generateWeeklyCronExpression(interval)
224
165
  break
225
166
  case 'month':
226
- const monthDelay = interval.frg_interval
227
- cronExpression = generateMonthlyCronExpression(
228
- monthDelay,
229
- new Date(interval.frg_start_on_time)
230
- )
167
+ cronExpression = cron.generateMonthlyCronExpression(interval)
231
168
  break
232
169
  default:
233
170
  cronExpression = '* * * * *'
@@ -0,0 +1,67 @@
1
+ import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
2
+
3
+ export const generateHourlyCronExpression = (
4
+ data: UI_I_ScheduleNewTasksForm
5
+ ): string => {
6
+ const startTimestamp = Math.floor(
7
+ new Date(data.frg_start_on_time).getTime() / 1000
8
+ )
9
+ const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
10
+
11
+ // Генерируем cron-выражение
12
+ return endTimestamp
13
+ ? `* * * * * ${startTimestamp}-${endTimestamp}:${data.frg_interval}-0-0-0`
14
+ : `* * * * * ${startTimestamp}:${data.frg_interval}-0-0-0`
15
+ }
16
+ export const generateWeeklyCronExpression = (
17
+ data: UI_I_ScheduleNewTasksForm
18
+ ): string => {
19
+ const { frg_on_week_days } = data
20
+
21
+ const startTimestamp = Math.floor(
22
+ new Date(data.frg_start_on_time).getTime() / 1000
23
+ )
24
+ const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
25
+ const daysOfWeek = frg_on_week_days.join(',')
26
+
27
+ return endTimestamp
28
+ ? `* * * * ${daysOfWeek} ${startTimestamp}-${endTimestamp}:0-0-0-${data.frg_interval}`
29
+ : `* * * * ${daysOfWeek} ${startTimestamp}:0-0-0-${data.frg_interval}`
30
+ }
31
+
32
+ export const generateDailyCronExpression = (
33
+ data: UI_I_ScheduleNewTasksForm
34
+ ): string => {
35
+ const startTimestamp = Math.floor(
36
+ new Date(data.frg_start_on_time).getTime() / 1000
37
+ )
38
+ const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
39
+
40
+ // Генерируем cron-выражение
41
+ return endTimestamp
42
+ ? `* * * * * ${startTimestamp}-${endTimestamp}:0-${data.frg_interval}-0-0`
43
+ : `* * * * * ${startTimestamp}:0-${data.frg_interval}-0-0`
44
+ }
45
+
46
+ export const generateMonthlyCronExpression = (
47
+ data: UI_I_ScheduleNewTasksForm
48
+ ): string => {
49
+ const { frg_interval, frg_monthly_day, frq_week_day, frq_ordinal_number } =
50
+ data
51
+
52
+ const startTimestamp = Math.floor(
53
+ new Date(data.frg_start_on_time).getTime() / 1000
54
+ )
55
+ const endTimestamp = Math.floor(new Date(data.frg_end_time).getTime() / 1000)
56
+
57
+ const daysOfWeek = `${frq_week_day}#${frq_ordinal_number}`
58
+
59
+ const timestamp = endTimestamp
60
+ ? `${startTimestamp}-${endTimestamp}`
61
+ : startTimestamp
62
+
63
+ // Генерируем cron-выражение
64
+ return data.frg_monthly_mode === 'week'
65
+ ? `* * * * * ${timestamp}:0-0-${frg_interval}-${daysOfWeek}`
66
+ : `* * ${frg_monthly_day} */${frg_interval} * ${timestamp}:0-0-0-0`
67
+ }
@@ -11,12 +11,13 @@ export const scheduledTaskDefaultFormFunc = (): UI_I_ScheduleNewTasksForm => {
11
11
  frequency: '',
12
12
  frg_after_startup: 0,
13
13
  frg_interval: 1,
14
- frg_end_time: null,
15
- frg_start_on_time: null,
16
- frg_monthly_day: 0,
14
+ frg_end_time: '',
15
+ frg_start_on_time: '',
16
+ frg_monthly_mode: 'day',
17
+ frg_monthly_day: 1,
17
18
  frq_week_day: '',
18
19
  frq_ordinal_number: '',
19
- frg_on_time: null,
20
+ frg_on_time: '',
20
21
  frg_on_week_days: [],
21
22
  }
22
23
  }
@@ -9,12 +9,13 @@ export interface UI_I_ScheduleNewTasksForm {
9
9
  toggle: boolean
10
10
  frg_after_startup: number
11
11
  frg_interval: number
12
- frg_end_time: number | null
13
- frg_start_on_time: number | null
12
+ frg_end_time: string
13
+ frg_start_on_time: string
14
+ frg_monthly_mode: 'day' | 'week'
14
15
  frg_monthly_day: number
15
16
  frq_ordinal_number: string
16
17
  frq_week_day: UI_T_FrequencyWeeksDays
17
- frg_on_time: number | null
18
+ frg_on_time: string
18
19
  frg_on_week_days: number[]
19
20
  cron: string
20
21
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.4.311",
4
+ "version": "1.4.313",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",
@@ -1,103 +0,0 @@
1
- <template>
2
- <ui-modal
3
- test-id="change-password-modal"
4
- width="560px"
5
- :title="localization.common.changePassword"
6
- :subtitle="props.subtitle"
7
- class="change-password"
8
- @reset="emits('reset')"
9
- @submit="onSubmit"
10
- >
11
- <template #content>
12
- <ui-modal-block-standard>
13
- <p class="change-password__description">
14
- To keep your account secure, please make sure that your new password
15
- is different from any of your previous passwords.
16
- </p>
17
-
18
- <div class="change-password__form">
19
- <ui-input
20
- v-model="modelLocal.current_password"
21
- test-id="sign-in-username-field"
22
- :label="localization.auth.password"
23
- :error="errorText"
24
- type="password"
25
- ></ui-input>
26
-
27
- <ui-input
28
- v-model="modelLocal.new_password"
29
- test-id="sign-in-username-field"
30
- :label="localization.common.newPassword"
31
- :error="errorText"
32
- type="password"
33
- ></ui-input>
34
-
35
- <ui-input
36
- v-model="modelLocal.confirm_password"
37
- test-id="sign-in-username-field"
38
- :label="localization.common.confirmPassword"
39
- :error="errorText"
40
- type="password"
41
- ></ui-input>
42
- </div>
43
- </ui-modal-block-standard>
44
- </template>
45
-
46
- <template #footerLeftContent><span /></template>
47
- </ui-modal>
48
- </template>
49
-
50
- <script setup lang="ts">
51
- import type { UI_I_Localization } from '~//lib/models/interfaces'
52
- import type { UI_I_FormChangePassword } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/models/interfaces'
53
- import type { UI_T_Project } from '~/lib/models/types'
54
-
55
- const props = defineProps<{
56
- project: UI_T_Project
57
- subtitle: string
58
- }>()
59
- const emits = defineEmits<{
60
- (event: 'hide'): void
61
- (event: 'reset'): void
62
- (event: 'submit'): void
63
- }>()
64
- const modelLocal = defineModel<UI_I_FormChangePassword>({ required: true })
65
-
66
- const localization = computed<UI_I_Localization>(() => useLocal())
67
-
68
- // const isValid = ref<boolean>(false)
69
- const errorText = ref<string>('')
70
-
71
- // const showValidationErrors = (text: string): void => {
72
- // isValid.value = true
73
- // errorText.value = text
74
- // }
75
-
76
- // const onHideModal = (): void => {
77
- // emits('hide')
78
- // setForm()
79
- // isValid.value = false
80
- // }
81
-
82
- const onSubmit = (): void => {
83
- // const { } = modelLocal.value
84
- errorText.value = 'asdaldjlkdjkadj'
85
- }
86
- </script>
87
-
88
- <style lang="scss" scoped>
89
- @import 'assets/scss/common/mixins.scss';
90
- .change-password {
91
- &__description {
92
- color: #9da6ad;
93
- font-size: 12px;
94
- font-weight: 400;
95
- line-height: 14.52px;
96
- margin-bottom: 20px;
97
- }
98
- &__form {
99
- @include flex($dir: column);
100
- row-gap: 18px;
101
- }
102
- }
103
- </style>
@@ -1,209 +0,0 @@
1
- <template>
2
- <atoms-modal
3
- width="580px"
4
- test-id="change-password"
5
- show
6
- :title="localization.common.changePassword"
7
- :second-title="props.hostname"
8
- :disabled-submit="buttonDisabled"
9
- @hide="onHideModal"
10
- @submit="onChangePassword"
11
- >
12
- <template #modalBody>
13
- <form id="change-password-form" class="compact" @submit.prevent>
14
- <section class="form-block">
15
- <div class="form-group">
16
- <label for="current-password-field"
17
- >{{ localization.common.currentPassword }}:</label
18
- >
19
- <input
20
- id="current-password-field"
21
- v-model="form.password.value"
22
- data-id="change-password-input"
23
- type="password"
24
- />
25
- </div>
26
-
27
- <div class="form-group">
28
- <label for="new-password-field"
29
- >{{ localization.common.newPassword }}:</label
30
- >
31
-
32
- <div class="form-group__input">
33
- <atoms-tooltip-error
34
- :has-error="isValid"
35
- selector="#new-password-field"
36
- >
37
- <template #elem>
38
- <input
39
- id="new-password-field"
40
- v-model="form.newPassword.value"
41
- data-id="new-password-input"
42
- type="password"
43
- />
44
- </template>
45
- <template #content>{{ errorText }}</template>
46
- </atoms-tooltip-error>
47
- <atoms-the-icon
48
- v-show="isValid"
49
- class="is-error tooltip-trigger"
50
- name="info"
51
- />
52
- </div>
53
- </div>
54
-
55
- <div class="form-group">
56
- <label for="confirm-password-field"
57
- >{{ localization.common.confirmPassword }}:</label
58
- >
59
-
60
- <div class="form-group__input">
61
- <atoms-tooltip-error
62
- :has-error="isValid"
63
- selector="#confirm-password-field"
64
- >
65
- <template #elem>
66
- <input
67
- id="confirm-password-field"
68
- v-model="form.confirmPassword.value"
69
- data-id="confirm-password-input"
70
- type="password"
71
- />
72
- </template>
73
- <template #content>{{ errorText }}</template>
74
- </atoms-tooltip-error>
75
- <atoms-the-icon
76
- v-show="isValid"
77
- class="is-error tooltip-trigger"
78
- name="info"
79
- />
80
- </div>
81
- </div>
82
- </section>
83
- </form>
84
- </template>
85
- </atoms-modal>
86
- </template>
87
-
88
- <script setup lang="ts">
89
- import type { UI_I_Localization } from '~/lib/models/interfaces'
90
- import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
91
- import type {
92
- UI_I_ChangePasswordBodyRequest,
93
- UI_I_FormChangePassword,
94
- } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/models/interfaces'
95
- import type { UI_T_Project } from '~/lib/models/types'
96
- import { defaultFormFunc } from '~/components/common/layout/theHeader/userMenu/modals/changePassword/lib/config/form'
97
-
98
- const props = defineProps<{
99
- hostname: string
100
- project: UI_T_Project
101
- }>()
102
- const emits = defineEmits<{
103
- (event: 'hide'): void
104
- }>()
105
-
106
- const localization = computed<UI_I_Localization>(() => useLocal())
107
- const { $store, $validation }: any = useNuxtApp()
108
- const validation = $validation.call({})
109
-
110
- const isValid = ref<boolean>(false)
111
- const errorText = ref<string>('')
112
- const form = ref<UI_I_FormChangePassword>(
113
- useDeepCopy(defaultFormFunc(localization.value))
114
- )
115
-
116
- const setForm = (): void => {
117
- form.value = useDeepCopy(defaultFormFunc(localization.value))
118
- validation.setForm(form)
119
- }
120
- setForm()
121
-
122
- const buttonDisabled = computed<boolean>(() => {
123
- const { password, confirmPassword, newPassword } = form.value
124
- return (
125
- password.value &&
126
- confirmPassword.value &&
127
- newPassword.value !== confirmPassword.value
128
- )
129
- })
130
-
131
- const onChangePassword = async (): Promise<void> => {
132
- const valid = validation.touch()
133
- const { newPassword, password } = form.value
134
-
135
- if (newPassword.value === password.value) {
136
- showValidationErrors(localization.value.common.newPasswordMustDifferentOld)
137
- return
138
- }
139
- if (!valid.isValid) {
140
- showValidationErrors(valid.errors.confirmPassword[0])
141
- return
142
- }
143
-
144
- onHideModal()
145
-
146
- const sendData: UI_I_ChangePasswordBodyRequest = {
147
- current_password: password.value,
148
- new_password: newPassword.value,
149
- }
150
-
151
- let url = ''
152
- if (props.project === 'sphere') {
153
- const { id } = useLocalStorage('userData')
154
-
155
- url = `ui/users/${id}/passwd`
156
- } else if (props.project === 'procurator') {
157
- url = '/ui/passwd'
158
- }
159
-
160
- const { error } = await useMyFetch<never, API_UI_I_Error>(url, {
161
- method: 'POST',
162
- body: sendData,
163
- key: Date.now().toString(),
164
- })
165
-
166
- if (error.value?.data && error.value.data.error_code !== 0) {
167
- $store.dispatch('main/A_SHOW_NOTIFICATION', {
168
- status: 'error',
169
- headline: localization.value.common.operationFailed,
170
- messages: [
171
- {
172
- title: 'Error',
173
- descriptions: [error.value.data.error_message],
174
- },
175
- ],
176
- })
177
- }
178
- }
179
-
180
- const showValidationErrors = (text: string): void => {
181
- isValid.value = true
182
- errorText.value = text
183
- }
184
-
185
- const onHideModal = (): void => {
186
- emits('hide')
187
- setForm()
188
- isValid.value = false
189
- }
190
- </script>
191
-
192
- <style lang="scss" scoped>
193
- .form-block {
194
- .form-group {
195
- &:not(:first-child) input {
196
- width: 100%;
197
- }
198
- &__input {
199
- display: flex;
200
- width: 100%;
201
- }
202
- }
203
-
204
- svg {
205
- width: 24px;
206
- height: 24px;
207
- }
208
- }
209
- </style>