@worksafevictoria/wcl7.5 1.18.1 → 1.19.0-beta.6

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.
@@ -1,52 +1,52 @@
1
1
  <script setup>
2
- import { computed } from 'vue'
2
+ import { ref, computed } from 'vue'
3
3
  import { BModal, BFormInput } from 'bootstrap-vue-next'
4
4
  import CtaButton from './../../../SubComponents/CtaButton/index.vue'
5
+ import { PlannerToStorage } from './PlannersStorage.js'
5
6
 
6
- // props from parent
7
+ /* -----------------------
8
+ Props / Emits
9
+ ------------------------ */
7
10
  const props = defineProps({
8
11
  modelValue: {
9
12
  type: Boolean,
10
- default: false, // used by v-model on PlannerNameModal
11
- },
12
- value: {
13
- type: String,
14
- default: '', // used by v-model:value on PlannerNameModal
13
+ default: false,
15
14
  },
16
15
  })
17
16
 
18
- const emit = defineEmits([
19
- 'update:modelValue', // for v-model (show/hide)
20
- 'update:value', // for v-model:value (input text)
21
- 'onsubmit', // custom event to send value to parent
22
- ])
17
+ const emit = defineEmits(['update:modelValue', 'onsubmit'])
18
+
19
+ /* -----------------------
20
+ State
21
+ ------------------------ */
22
+ const inputValue = ref('')
23
23
 
24
- // proxy for v-model on <b-modal>
24
+ /* -----------------------
25
+ Modal proxy
26
+ ------------------------ */
25
27
  const show = computed({
26
28
  get: () => props.modelValue,
27
29
  set: (val) => emit('update:modelValue', val),
28
30
  })
29
31
 
30
- // proxy for v-model on input (goes to parent)
31
- const inputValue = computed({
32
- get: () => props.value,
33
- set: (val) => emit('update:value', val),
34
- })
35
-
32
+ /* -----------------------
33
+ Submit
34
+ ------------------------ */
36
35
  function handleSubmit() {
37
36
  const trimmed = inputValue.value.trim()
38
- console.log('handle Submit', trimmed)
37
+ console.log('handleSubmit:', trimmed)
39
38
 
40
39
  if (!trimmed) return
41
40
 
42
- // emit value to parent
43
- emit('onsubmit', trimmed)
41
+ // Save to localStorage
42
+ const planner = PlannerToStorage(trimmed)
44
43
 
45
- // close modal
46
- emit('update:modelValue', false)
44
+ // notify parent
45
+ emit('onsubmit', planner)
47
46
 
48
- // optional: clear input in parent
49
- emit('update:value', '')
47
+ // reset + close
48
+ inputValue.value = ''
49
+ emit('update:modelValue', false)
50
50
  }
51
51
  </script>
52
52
 
@@ -59,30 +59,27 @@ function handleSubmit() {
59
59
  no-footer
60
60
  size="lg"
61
61
  >
62
- <template #default="{ close }">
63
- <div class="p-3">
64
- <h3 class="fw-bold mb-3 modal-title__new-planner">Name your planner</h3>
65
- <p class="mb-4 modal-description__new-planner">
66
- Give your planner a name so you can easily find it and pick up where
67
- you left off.
68
- </p>
69
-
70
- <label for="modal2CB" class="fw-bold mb-2">
71
- Injured workers first name
72
- </label>
73
-
74
- <BFormInput
75
- id="modal2CB"
76
- name="modal2CB"
77
- placeholder=""
78
- v-model="inputValue"
79
- class="mb-4 input__new-planner"
80
- @keyup.enter="handleSubmit"
81
- />
82
-
83
- <CtaButton ref="calNextBtn" @click="handleSubmit">Next</CtaButton>
84
- </div>
85
- </template>
62
+ <div class="p-3">
63
+ <h3 class="fw-bold mb-3 modal-title__new-planner">Name your planner</h3>
64
+
65
+ <p class="mb-4 modal-description__new-planner">
66
+ Give your planner a name so you can easily find it and pick up where you
67
+ left off.
68
+ </p>
69
+
70
+ <label for="modal2CB" class="fw-bold mb-2">
71
+ Injured workers first name
72
+ </label>
73
+
74
+ <BFormInput
75
+ id="modal2CB"
76
+ v-model="inputValue"
77
+ class="mb-4 input__new-planner"
78
+ @keyup.enter="handleSubmit"
79
+ />
80
+
81
+ <CtaButton @click="handleSubmit">Next</CtaButton>
82
+ </div>
86
83
  </b-modal>
87
84
  </template>
88
85
 
@@ -0,0 +1,29 @@
1
+ import { ref } from 'vue'
2
+
3
+ const STORAGE_KEY = 'planners'
4
+
5
+ export function getPlanners() {
6
+ const saved = localStorage.getItem(STORAGE_KEY)
7
+ return saved ? JSON.parse(saved) : []
8
+ }
9
+
10
+ export function savePlanners(planners) {
11
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(planners))
12
+ }
13
+
14
+ export function PlannerToStorage(name) {
15
+ if (!name.trim()) return null
16
+
17
+ const planners = getPlanners()
18
+
19
+ const planner = {
20
+ id: Date.now(),
21
+ name,
22
+ tasksCompleted: [],
23
+ }
24
+
25
+ planners.push(planner)
26
+ savePlanners(planners)
27
+
28
+ return planner
29
+ }