@@ -7,10 +6,10 @@
- Change Case Visibility
+ Change {{ subjectTitle }} Visibility
- You are about to change the case visibility from {{ visibility }} to
- {{ toggleVisibility }}{{ visibility }} to {{ toggleVisibility }}.
@@ -26,9 +25,14 @@
import { ref, watch, computed } from "vue"
import { useStore } from "vuex"
import CaseApi from "@/case/api"
+import IncidentApi from "@/incident/api"
const props = defineProps({
- caseVisibility: {
+ subjectVisibility: {
+ type: String,
+ required: true,
+ },
+ subjectType: {
type: String,
required: true,
},
@@ -36,14 +40,16 @@ const props = defineProps({
const store = useStore()
const dialog = ref(false)
-const visibility = ref(props.caseVisibility)
+const visibility = ref(props.subjectVisibility)
const lockIcon = computed(() => (visibility.value === "Open" ? "mdi-lock-open" : "mdi-lock"))
const toggleVisibility = computed(() => (visibility.value === "Open" ? "Restricted" : "Open"))
+const subjectTitle = computed(() => (props.subjectType === "incident" ? "Incident" : "Case"))
+
watch(
- () => props.caseVisibility,
+ () => props.subjectVisibility,
(newVal) => {
visibility.value = newVal
},
@@ -51,25 +57,25 @@ watch(
)
async function updateVisibility() {
- const caseDetails = store.state.case_management.selected
+ const subject = store.state[props.subjectType].selected
const previousVisibility = visibility.value // Store the previous visibility value
// Optimistically update the UI
visibility.value = toggleVisibility.value
- caseDetails.visibility = visibility.value
+ subject.visibility = visibility.value
dialog.value = false
try {
- await CaseApi.update(caseDetails.id, caseDetails)
+ await (props.subjectType === "incident" ? IncidentApi : CaseApi).update(subject.id, subject)
} catch (e) {
- console.error("Failed to update case visibility", e)
+ console.error(`Failed to update ${props.subjectType} visibility`, e)
// If the API call fails, revert the visibility change and show a toast
visibility.value = previousVisibility
store.commit(
"notification_backend/addBeNotification",
{
- text: "Failed to update case visibility",
+ text: `Failed to update ${props.subjectType} visibility`,
type: "error",
},
{ root: true }