Mandant switcher
This commit is contained in:
@ -4,7 +4,7 @@ import {
|
|||||||
MoreHorizontal,
|
MoreHorizontal,
|
||||||
StarOff,
|
StarOff,
|
||||||
Trash2,
|
Trash2,
|
||||||
} from "lucide-react"
|
} from 'lucide-react'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@ -12,7 +12,7 @@ import {
|
|||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from '@/components/ui/dropdown-menu'
|
||||||
import {
|
import {
|
||||||
SidebarGroup,
|
SidebarGroup,
|
||||||
SidebarGroupLabel,
|
SidebarGroupLabel,
|
||||||
@ -21,16 +21,16 @@ import {
|
|||||||
SidebarMenuButton,
|
SidebarMenuButton,
|
||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
useSidebar,
|
useSidebar,
|
||||||
} from "@/components/ui/sidebar"
|
} from '@/components/ui/sidebar'
|
||||||
|
|
||||||
export function NavFavorites({
|
export function NavFavorites({
|
||||||
favorites,
|
favorites,
|
||||||
}: {
|
}: {
|
||||||
favorites: {
|
favorites: Array<{
|
||||||
name: string
|
name: string
|
||||||
url: string
|
url: string
|
||||||
emoji: string
|
emoji: string
|
||||||
}[]
|
}>
|
||||||
}) {
|
}) {
|
||||||
const { isMobile } = useSidebar()
|
const { isMobile } = useSidebar()
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ export function NavFavorites({
|
|||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent
|
<DropdownMenuContent
|
||||||
className="w-56 rounded-lg"
|
className="w-56 rounded-lg"
|
||||||
side={isMobile ? "bottom" : "right"}
|
side={isMobile ? 'bottom' : 'right'}
|
||||||
align={isMobile ? "end" : "start"}
|
align={isMobile ? 'end' : 'start'}
|
||||||
>
|
>
|
||||||
<DropdownMenuItem>
|
<DropdownMenuItem>
|
||||||
<StarOff className="text-muted-foreground" />
|
<StarOff className="text-muted-foreground" />
|
||||||
|
|||||||
@ -1,23 +1,10 @@
|
|||||||
import { useAnsprechpartner, useAnsprechpartnerEditMutation } from '../queries'
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { useAnsprechpartner } from '../queries'
|
||||||
|
|
||||||
function AnsprechpartnerDetail({ id }: { id: number }) {
|
function AnsprechpartnerDetail({ id }: { id: number }) {
|
||||||
const { data } = useAnsprechpartner(id)
|
const { data: ansprechpartner } = useAnsprechpartner(id)
|
||||||
const { mutate } = useAnsprechpartnerEditMutation()
|
|
||||||
|
|
||||||
return (
|
return <div></div>
|
||||||
<div>
|
|
||||||
{JSON.stringify(data)}
|
|
||||||
<button
|
|
||||||
onClick={(e) => {
|
|
||||||
const newAnsprechparter = data!
|
|
||||||
newAnsprechparter.first_name += '1'
|
|
||||||
mutate(newAnsprechparter)
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Edit Ansprechpartner
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AnsprechpartnerDetail
|
export default AnsprechpartnerDetail
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
import {
|
||||||
|
useMutation,
|
||||||
|
useQuery,
|
||||||
|
useQueryClient,
|
||||||
|
useSuspenseQuery,
|
||||||
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
const ansprechpartnerKeys = {
|
const ansprechpartnerKeys = {
|
||||||
all: ['ansprechpartner'] as const,
|
all: ['ansprechpartner'] as const,
|
||||||
@ -7,7 +12,7 @@ const ansprechpartnerKeys = {
|
|||||||
detail: (id: number) => [...ansprechpartnerKeys.details(), id] as const,
|
detail: (id: number) => [...ansprechpartnerKeys.details(), id] as const,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ansprechpartner = {
|
export type Ansprechpartner = {
|
||||||
ID: number
|
ID: number
|
||||||
CreatedAt: Date
|
CreatedAt: Date
|
||||||
UpdatedAt: Date | undefined
|
UpdatedAt: Date | undefined
|
||||||
@ -37,7 +42,7 @@ export function useAllAnsprechpartners() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useAnsprechpartner(id: number) {
|
export function useAnsprechpartner(id: number) {
|
||||||
return useQuery<Ansprechpartner>({
|
return useSuspenseQuery<Ansprechpartner>({
|
||||||
queryKey: ansprechpartnerKeys.detail(id),
|
queryKey: ansprechpartnerKeys.detail(id),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const data = await fetch('http://localhost:3000/v1/ansprechpartner/' + id)
|
const data = await fetch('http://localhost:3000/v1/ansprechpartner/' + id)
|
||||||
|
|||||||
@ -26,31 +26,29 @@ export function TeamSwitcher() {
|
|||||||
const { data: currentMandant } = useCurrentMandant()
|
const { data: currentMandant } = useCurrentMandant()
|
||||||
const { data: mandanten } = useAllMandanten()
|
const { data: mandanten } = useAllMandanten()
|
||||||
|
|
||||||
const { mutate } = useCurrentMandantMutation()
|
const editCurrentTeamMutation = useCurrentMandantMutation()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('AddEvent')
|
|
||||||
const down = (e: KeyboardEvent) => {
|
const down = (e: KeyboardEvent) => {
|
||||||
console.log('Keydown: ' + e.key)
|
|
||||||
|
|
||||||
let numKey = Number(e.key)
|
let numKey = Number(e.key)
|
||||||
|
|
||||||
if ((e.metaKey || e.ctrlKey) && !Number.isNaN(numKey)) {
|
if ((e.metaKey || e.ctrlKey) && !Number.isNaN(numKey)) {
|
||||||
console.log('CMD | META-before & ' + numKey)
|
|
||||||
|
|
||||||
numKey -= 1
|
numKey -= 1
|
||||||
|
if (mandanten && currentMandant) {
|
||||||
|
const mandant = mandanten[numKey]
|
||||||
|
|
||||||
console.log('CMD | META & ' + numKey)
|
if (mandant.id === currentMandant.id) {
|
||||||
if (mandanten) {
|
return
|
||||||
mutate(mandanten[numKey])
|
}
|
||||||
console.log('MUTATED ' + mandanten[numKey])
|
|
||||||
|
editCurrentTeamMutation.mutate(mandanten[numKey])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('keydown', down)
|
document.addEventListener('keydown', down)
|
||||||
return () => document.removeEventListener('keydown', down)
|
return () => document.removeEventListener('keydown', down)
|
||||||
}, [mandanten])
|
}, [mandanten, currentMandant])
|
||||||
|
|
||||||
if (!currentMandant || !mandanten) return <p>Loading...</p>
|
if (!currentMandant || !mandanten) return <p>Loading...</p>
|
||||||
|
|
||||||
@ -102,12 +100,16 @@ export function TeamSwitcher() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function MandantDMI({ mandant, index }: { mandant: Mandant; index: number }) {
|
function MandantDMI({ mandant, index }: { mandant: Mandant; index: number }) {
|
||||||
const { mutate } = useCurrentMandantMutation()
|
const { data: currentMandant } = useCurrentMandant()
|
||||||
|
const editCurrentMandantMutaiton = useCurrentMandantMutation()
|
||||||
|
|
||||||
|
if (!currentMandant) return <p>Loading...</p>
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
key={mandant.name}
|
key={mandant.name}
|
||||||
onClick={() => mutate(mandant)}
|
onClick={() => editCurrentMandantMutaiton.mutate(mandant)}
|
||||||
|
disabled={mandant.id === currentMandant.id}
|
||||||
className="gap-2 p-2"
|
className="gap-2 p-2"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -1,7 +1,14 @@
|
|||||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||||
|
|
||||||
export function getContext() {
|
export function getContext() {
|
||||||
const queryClient = new QueryClient()
|
const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
experimental_prefetchInRender: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
queryClient,
|
queryClient,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { Suspense } from 'react'
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
import AnsprechpartnerDetail from '@/features/CRM/components/detail'
|
import AnsprechpartnerDetail from '@/features/CRM/components/detail'
|
||||||
|
|
||||||
@ -7,8 +8,8 @@ export const Route = createFileRoute('/_sidebar/about')({
|
|||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<Suspense fallback={<p>Loading......</p>}>
|
||||||
<AnsprechpartnerDetail id={8} />
|
<AnsprechpartnerDetail id={8} />
|
||||||
</div>
|
</Suspense>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user