1<template>
2 <Dialog
3 v-model:open="dialog.show"
4 :title="renameDialogOptions.title"
5 :message="renameDialogOptions.message"
6 >
7 <template #default>
8 <FormControl
9 v-model="teamName"
10 :label="__('Title')"
11 :placeholder="__('Product Experts')"
12 />
13 </template>
14 <template #actions>
15 <Button
16 variant="solid"
17 class="flex w-full"
18 @click="renameTeam"
19 :loading="renameTeamResource.loading"
20 :disabled="teamName == dialog.teamName || teamName.trim() == ''"
21 >
22 Confirm
23 </Button>
24 </template>
25 </Dialog>
26</template>
27
28<script setup lang="ts">
29import { __ } from "@/translation";
30import { createResource, Dialog, toast } from "frappe-ui";
31import { computed, ref, watch } from "vue";
32
33const emit = defineEmits(["onRename"]);
34
35const dialog = defineModel<{
36 show: boolean;
37 teamName: string;
38}>();
39const teamName = ref(dialog.value.teamName);
40
41const renameTeamResource = createResource({
42 url: "frappe.client.rename_doc",
43 makeParams() {
44 return {
45 doctype: "OD Team",
46 old_name: dialog.value.teamName,
47 new_name: teamName.value,
48 };
49 },
50 validate(params) {
51 if (!params.new_name) return __("New title is required");
52 if (params.new_name === params.old_name)
53 return __("New and old title cannot be same");
54 },
55 onSuccess(data) {
56 toast.success(__("Team renamed successfully."));
57 dialog.value.show = false;
58 emit("onRename", data);
59 },
60});
61
62const renameDialogOptions = computed(() => ({
63 title: __("Rename team"),
64 message: __("Enter the new name for the team"),
65}));
66
67function renameTeam() {
68 renameTeamResource.submit();
69}
70
71watch(
72 () => dialog.value.show,
73 () => {
74 teamName.value = dialog.value.teamName;
75 }
76);
77</script>
78