Skip to content

Commit

Permalink
fix: remove user store (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssiyad authored Sep 27, 2023
1 parent f47e877 commit 6fcb57b
Show file tree
Hide file tree
Showing 28 changed files with 212 additions and 171 deletions.
7 changes: 6 additions & 1 deletion desk/src/components/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
<template #top>
<span class="text-base">
<span class="flex items-center justify-between">
<UserAvatar :user="authStore.userId" expand strong />
<UserAvatar
:name="authStore.userName"
:image="authStore.userImage"
expand
strong
/>
<slot name="top-right" />
</span>
<slot name="top-bottom" />
Expand Down
12 changes: 4 additions & 8 deletions desk/src/components/TimelineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<span>
<LucideDot class="absolute -left-3 h-6 w-6 bg-white text-gray-500" />
<div class="mb-1 font-medium text-gray-900 first-letter:capitalize">
{{ user?.full_name || user }} {{ action }}
{{ user.name }} {{ action }}
</div>
<Tooltip :text="dayjs(date).long()">
<div class="text-gray-700 first-letter:capitalize">
Expand All @@ -15,17 +15,13 @@
<script setup lang="ts">
import { Tooltip } from "frappe-ui";
import { dayjs } from "@/dayjs";
import { useUserStore } from "@/stores/user";
import { UserInfo } from "@/types";
interface P {
user: string;
user: UserInfo;
date: string;
action?: string;
}
const props = withDefaults(defineProps<P>(), {
action: "",
});
const userStore = useUserStore();
const user = userStore.getUser(props.user);
defineProps<P>();
</script>
17 changes: 4 additions & 13 deletions desk/src/components/UserAvatar.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<template>
<div class="flex items-center gap-2">
<Avatar
:label="user?.full_name || props.user"
:image="image || user?.user_image"
v-bind="$attrs"
/>
<Avatar :label="name" :image="image" v-bind="$attrs" />
<span
v-if="expand"
class="truncate"
Expand All @@ -13,28 +9,23 @@
'font-medium': strong,
}"
>
{{ user?.full_name || props.user }}
{{ name }}
</span>
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
import { Avatar } from "frappe-ui";
import { useUserStore } from "@/stores/user";
interface P {
user?: string;
name: string;
image?: string;
expand?: boolean;
strong?: boolean;
}
const props = withDefaults(defineProps<P>(), {
user: "",
withDefaults(defineProps<P>(), {
image: "",
expand: false,
strong: false,
});
const { getUser } = useUserStore();
const user = computed(() => getUser(props.user));
</script>
2 changes: 1 addition & 1 deletion desk/src/components/notifications/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
:to="getRoute(n)"
@click="() => notificationStore.toggle()"
>
<UserAvatar :user="n.user_from" />
<UserAvatar v-bind="n.user_from" />
<span>
<div class="mb-2 leading-5">
<component :is="getBody(n)" v-bind="n" />
Expand Down
12 changes: 5 additions & 7 deletions desk/src/components/notifications/NotificationsMention.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<template>
<span class="space-x-1 text-gray-700">
<span class="font-medium text-gray-900">{{ user.full_name || user }}</span>
<span class="font-medium text-gray-900">{{ user_from.name }}</span>
<span>mentioned you in ticket</span>
<span class="font-medium text-gray-900">{{ props.reference_ticket }}</span>
<span class="font-medium text-gray-900">{{ reference_ticket }}</span>
</span>
</template>

<script setup lang="ts">
import { useUserStore } from "@/stores/user";
import { UserInfo } from "@/types";
interface P {
user_from: string;
user_from: UserInfo;
reference_ticket: string;
}
const props = defineProps<P>();
const { getUser } = useUserStore();
const user = getUser(props.user_from);
defineProps<P>();
</script>
7 changes: 6 additions & 1 deletion desk/src/pages/c-layout/CLayoutNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<Dropdown :options="options">
<template #default="{ open }">
<div class="flex cursor-pointer items-center gap-1">
<UserAvatar :user="authStore.userId" expand strong />
<UserAvatar
:name="authStore.userName"
:image="authStore.userImage"
expand
strong
/>
<div class="text-gray-700">
<Icon v-if="open" icon="lucide:chevron-up" />
<Icon v-else icon="lucide:chevron-down" />
Expand Down
27 changes: 6 additions & 21 deletions desk/src/pages/ticket/TicketAgentActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<Autocomplete
:options="agentStore.dropdown"
:value="
assignedTo
data.assignee
? {
label: assignedTo?.full_name,
value: assignedTo?.name,
label: data.assignee.name,
value: data.assignee.email,
}
: null
"
Expand All @@ -15,18 +15,11 @@
>
<template #prefix>
<Avatar
v-if="assignedTo"
v-if="data.assignee"
class="mr-2"
size="sm"
:label="assignedTo?.full_name"
:image="assignedTo?.user_image"
/>
</template>
<template #item-prefix="{ option }">
<Avatar
class="mr-2"
:label="userStore.getUser(option.value)?.full_name"
:image="userStore.getUser(option.value)?.user_image"
:label="data.assignee.name"
:image="data.assignee.image"
/>
</template>
</Autocomplete>
Expand Down Expand Up @@ -95,21 +88,13 @@ import { emitter } from "@/emitter";
import { createToast } from "@/utils";
import { useAgentStore } from "@/stores/agent";
import { useTicketStatusStore } from "@/stores/ticketStatus";
import { useUserStore } from "@/stores/user";
import { useError } from "@/composables/error";
import { ITicket } from "./symbols";
const ticket = inject(ITicket);
const agentStore = useAgentStore();
const ticketStatusStore = useTicketStatusStore();
const userStore = useUserStore();
const data = computed(() => ticket.data);
const assignedTo = computed(() => {
const assignJson = JSON.parse(data.value._assign);
const arr = Array.isArray(assignJson) ? assignJson : [];
const user = arr.slice(-1).pop();
return userStore.getUser(user);
});
function assignAgent(agent: string) {
createResource({
Expand Down
11 changes: 6 additions & 5 deletions desk/src/pages/ticket/TicketComment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="my-4 rounded border bg-cyan-50 p-4">
<div class="mb-4 flex items-center justify-between">
<div class="flex items-center gap-0.5 text-base">
<UserAvatar :user="sender" size="lg" expand strong />
<UserAvatar v-bind="user" size="lg" expand strong />
<Icon icon="lucide:dot" class="text-gray-500" />
<Tooltip :text="dayjs(date).long()">
<div class="text-gray-600">
Expand Down Expand Up @@ -36,20 +36,21 @@ import { createResource, Badge, Button, Dropdown, Tooltip } from "frappe-ui";
import { Icon } from "@iconify/vue";
import { dayjs } from "@/dayjs";
import { emitter } from "@/emitter";
import { useAuthStore } from "@/stores/auth";
import { createToast } from "@/utils";
import { useAuthStore } from "@/stores/auth";
import { UserInfo } from "@/types";
import { UserAvatar } from "@/components";
interface P {
content: string;
date: string;
isPinned: number;
name: string;
sender: string;
user: UserInfo;
}
const props = defineProps<P>();
const { content, name, sender, isPinned } = toRefs(props);
const { content, name, isPinned, user } = toRefs(props);
const authStore = useAuthStore();
const IconTrash = h(Icon, { icon: "lucide:trash-2" });
const IconPin = h(Icon, { icon: "lucide:pin" });
Expand All @@ -65,7 +66,7 @@ const options = computed(() =>
label: "Delete",
icon: IconTrash,
onClick: () => deleteComment.submit(),
isHidden: sender.value !== authStore.userId,
isHidden: user.value.email !== authStore.userId,
},
].filter((i) => !i.isHidden)
);
Expand Down
5 changes: 3 additions & 2 deletions desk/src/pages/ticket/TicketCommunication.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="mx-3 pt-6">
<div class="mb-4 flex items-center justify-between text-base">
<div class="flex items-center gap-0.5">
<UserAvatar :user="sender" size="lg" expand strong />
<UserAvatar v-bind="user" size="lg" expand strong />
<Icon icon="lucide:dot" class="text-gray-500" />
<Tooltip :text="dayjs(date).long()">
<div class="text-gray-600">
Expand Down Expand Up @@ -30,6 +30,7 @@ import { Tooltip } from "frappe-ui";
import sanitizeHtml from "sanitize-html";
import { Icon } from "@iconify/vue";
import { dayjs } from "@/dayjs";
import { UserInfo } from "@/types";
import { AttachmentItem, UserAvatar } from "@/components";
interface Attachment {
Expand All @@ -40,7 +41,7 @@ interface Attachment {
interface P {
content: string;
date: string;
sender: string;
user: UserInfo;
cc?: string;
bcc?: string;
attachments?: Attachment[];
Expand Down
4 changes: 2 additions & 2 deletions desk/src/pages/ticket/TicketConversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
:name="c.name"
:content="c.content"
:date="c.creation"
:sender="c.commented_by"
:user="c.user"
:is-pinned="c.is_pinned"
/>
<TicketCommunication
v-else
:content="c.content"
:date="c.creation"
:sender="c.sender"
:user="c.user"
:sender-image="c.sender"
:cc="c.cc || ''"
:bcc="c.bcc || ''"
Expand Down
2 changes: 1 addition & 1 deletion desk/src/pages/ticket/TicketHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="mb-4 ml-4"
>
<TimelineItem
:user="event.owner"
:user="event.user"
:date="event.creation"
:action="event.action"
/>
Expand Down
11 changes: 10 additions & 1 deletion desk/src/pages/ticket/TicketTextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<span class="flex">
<slot name="bottom-left" />
<FileUploader
:upload-args="{
doctype: 'HD Ticket',
folder: 'Home/Helpdesk',
private: true,
}"
@success="(f: File) => $emit('update:attachments', [...attachments, f])"
>
<template #default="{ openFileSelector }">
Expand Down Expand Up @@ -59,7 +64,11 @@
class="flex w-full cursor-pointer items-center gap-2 rounded bg-gray-100 px-3.5 py-2 hover:bg-gray-200"
@click="() => $emit('update:expand', !expand)"
>
<UserAvatar :user="authStore.userId" size="sm" />
<UserAvatar
:name="authStore.userName"
:image="authStore.userImage"
size="sm"
/>
<span class="text-base text-gray-700">
{{ placeholder }}
</span>
Expand Down
2 changes: 1 addition & 1 deletion desk/src/pages/ticket/TicketViews.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:key="event.name"
class="mb-4 ml-4"
>
<TimelineItem :user="event.viewed_by" :date="event.creation" />
<TimelineItem :user="event.user" :date="event.creation" />
</li>
</ol>
</div>
Expand Down
2 changes: 1 addition & 1 deletion desk/src/pages/tickets/TicketsAgent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const columns = [
},
{
label: "Assignee",
key: "_assign",
key: "assignee",
width: "w-40",
},
{
Expand Down
4 changes: 2 additions & 2 deletions desk/src/pages/tickets/TicketsAgentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
</span>
</span>
</template>
<template #_assign="{ data }">
<UserAvatar :user="getAssign(data._assign)" expand />
<template #assignee="{ data }">
<UserAvatar v-bind="data.assignee" expand />
</template>
<template #agreement_status="{ data }">
<Badge
Expand Down
2 changes: 0 additions & 2 deletions desk/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createRouter, createWebHistory } from "vue-router";
import { useAuthStore } from "@/stores/auth";
import { useUserStore } from "@/stores/user";
import { init as initTelemetry } from "@/telemetry";
import { AuthPages } from "./auth";
import { CustomerPages } from "./customer";
Expand Down Expand Up @@ -232,7 +231,6 @@ export const router = createRouter({
router.beforeEach(async (to) => {
const isAuthRoute = AUTH_ROUTES.includes(to.name);
const authStore = useAuthStore();
useUserStore();

try {
await initTelemetry();
Expand Down
8 changes: 4 additions & 4 deletions desk/src/stores/notification.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { computed, ref } from "vue";
import { defineStore } from "pinia";
import { createResource, createListResource } from "frappe-ui";
import { createResource } from "frappe-ui";
import { useAuthStore } from "@/stores/auth";
import { useError } from "@/composables/error";
import { createListManager } from "@/composables/listManager";
import { Notification, Resource } from "@/types";

export const useNotificationStore = defineStore("notification", () => {
const authStore = useAuthStore();
const visible = ref(false);
const resource: Resource<Array<Notification>> = createListResource({
const resource: Resource<Array<Notification>> = createListManager({
doctype: "HD Notification",
cache: "Notifications",
filters: {
Expand All @@ -24,9 +25,8 @@ export const useNotificationStore = defineStore("notification", () => {
"user_from",
"user_to",
],
orded_by: "creation desc",
orderBy: "creation desc",
auto: true,
debounce: 500,
});
const clear = createResource({
url: "helpdesk.helpdesk.doctype.hd_notification.utils.clear",
Expand Down
Loading

0 comments on commit 6fcb57b

Please sign in to comment.