context: rename contexts properly
This commit is contained in:
parent
a4608ead43
commit
d0e67a0f8a
@ -1,10 +1,10 @@
|
||||
import { ContactsFilter, ContactsList } from '@/components/contacts';
|
||||
import { ContactsFilterProvider } from '@/context/contacts-filter';
|
||||
import { ContactsContextProvider } from '@/context/contacts-context';
|
||||
import { Card } from '@repo/ui/components/ui/card';
|
||||
|
||||
export default function ContactsPage() {
|
||||
return (
|
||||
<ContactsFilterProvider>
|
||||
<ContactsContextProvider>
|
||||
<Card>
|
||||
<div className="flex flex-row items-center justify-between space-x-4 p-4">
|
||||
<h1 className="font-bold">Контакты</h1>
|
||||
@ -14,6 +14,6 @@ export default function ContactsPage() {
|
||||
<ContactsList />
|
||||
</div>
|
||||
</Card>
|
||||
</ContactsFilterProvider>
|
||||
</ContactsContextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { ScheduleContextProvider } from '@/context/schedule';
|
||||
import { DateContextProvider } from '@/context/date-context';
|
||||
import { type PropsWithChildren } from 'react';
|
||||
|
||||
export default async function Layout({ children }: Readonly<PropsWithChildren>) {
|
||||
return <ScheduleContextProvider>{children}</ScheduleContextProvider>;
|
||||
return <DateContextProvider>{children}</DateContextProvider>;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { ContactsFilterContext, type FilterType } from '@/context/contacts-filter';
|
||||
import { ContactsContext, type FilterType } from '@/context/contacts-context';
|
||||
import { Button } from '@repo/ui/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
@ -18,7 +18,7 @@ const filterLabels: Record<FilterType, string> = {
|
||||
};
|
||||
|
||||
export function ContactsFilter() {
|
||||
const { filter, setFilter } = use(ContactsFilterContext);
|
||||
const { filter, setFilter } = use(ContactsContext);
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import { LoadingSpinner } from '@/components/common/spinner';
|
||||
import { CardSectionHeader } from '@/components/ui';
|
||||
import { ContactsFilterProvider } from '@/context/contacts-filter';
|
||||
import { ContactsContextProvider } from '@/context/contacts-context';
|
||||
import { useCustomerContacts } from '@/hooks/api/contacts';
|
||||
// eslint-disable-next-line import/extensions
|
||||
import AvatarPlaceholder from '@/public/avatar/avatar_placeholder.png';
|
||||
@ -86,7 +86,7 @@ export function ContactsGridBase({ contacts, onSelect, selected, title }: Contac
|
||||
);
|
||||
}
|
||||
|
||||
export const MastersGrid = withContext(ContactsFilterProvider)(function () {
|
||||
export const MastersGrid = withContext(ContactsContextProvider)(function () {
|
||||
const { contacts, isLoading, setFilter } = useCustomerContacts();
|
||||
const masterId = useOrderStore((store) => store.masterId);
|
||||
const setMasterId = useOrderStore((store) => store.setMasterId);
|
||||
@ -107,7 +107,7 @@ export const MastersGrid = withContext(ContactsFilterProvider)(function () {
|
||||
);
|
||||
});
|
||||
|
||||
export const ClientsGrid = withContext(ContactsFilterProvider)(function () {
|
||||
export const ClientsGrid = withContext(ContactsContextProvider)(function () {
|
||||
const { contacts, isLoading, setFilter } = useCustomerContacts();
|
||||
const clientId = useOrderStore((store) => store.clientId);
|
||||
const setClientId = useOrderStore((store) => store.setClientId);
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import { ScheduleContext } from '@/context/schedule';
|
||||
import { DateContext } from '@/context/date-context';
|
||||
import { Calendar } from '@repo/ui/components/ui/calendar';
|
||||
import dayjs from 'dayjs';
|
||||
import { use } from 'react';
|
||||
|
||||
export function ScheduleCalendar() {
|
||||
const { selectedDate, setSelectedDate } = use(ScheduleContext);
|
||||
const { selectedDate, setSelectedDate } = use(DateContext);
|
||||
|
||||
return (
|
||||
<Calendar
|
||||
|
||||
@ -3,12 +3,12 @@
|
||||
import { SlotCard } from './components/slot-card';
|
||||
import { DaySlotAddForm } from './day-slot-add-form';
|
||||
import { LoadingSpinner } from '@/components/common/spinner';
|
||||
import { ScheduleContext } from '@/context/schedule';
|
||||
import { DateContext } from '@/context/date-context';
|
||||
import { useSlotsQuery } from '@/hooks/api/slots';
|
||||
import { use } from 'react';
|
||||
|
||||
export function DaySlotsList() {
|
||||
const { selectedDate } = use(ScheduleContext);
|
||||
const { selectedDate } = use(DateContext);
|
||||
const { data: { slots } = {}, isLoading } = useSlotsQuery({
|
||||
filters: { date: { eq: selectedDate } },
|
||||
});
|
||||
|
||||
@ -3,14 +3,15 @@
|
||||
import { createContext, type PropsWithChildren, useMemo, useState } from 'react';
|
||||
|
||||
export type FilterType = 'all' | 'clients' | 'masters';
|
||||
|
||||
type ContextType = { filter: FilterType; setFilter: (filter: FilterType) => void };
|
||||
|
||||
export const ContactsFilterContext = createContext<ContextType>({} as ContextType);
|
||||
export const ContactsContext = createContext<ContextType>({} as ContextType);
|
||||
|
||||
export function ContactsFilterProvider({ children }: Readonly<PropsWithChildren>) {
|
||||
export function ContactsContextProvider({ children }: Readonly<PropsWithChildren>) {
|
||||
const [filter, setFilter] = useState<FilterType>('all');
|
||||
|
||||
const value = useMemo(() => ({ filter, setFilter }), [filter, setFilter]);
|
||||
|
||||
return <ContactsFilterContext value={value}>{children}</ContactsFilterContext>;
|
||||
return <ContactsContext value={value}>{children}</ContactsContext>;
|
||||
}
|
||||
@ -7,12 +7,12 @@ type ContextType = {
|
||||
setSelectedDate: (date: Date) => void;
|
||||
};
|
||||
|
||||
export const ScheduleContext = createContext<ContextType>({} as ContextType);
|
||||
export const DateContext = createContext<ContextType>({} as ContextType);
|
||||
|
||||
export function ScheduleContextProvider({ children }: { readonly children: React.ReactNode }) {
|
||||
export function DateContextProvider({ children }: { readonly children: React.ReactNode }) {
|
||||
const [selectedDate, setSelectedDate] = useState(new Date());
|
||||
|
||||
const value = useMemo(() => ({ selectedDate, setSelectedDate }), [selectedDate]);
|
||||
|
||||
return <ScheduleContext value={value}>{children}</ScheduleContext>;
|
||||
return <DateContext value={value}>{children}</DateContext>;
|
||||
}
|
||||
@ -1,12 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import { useClientsQuery, useMastersQuery } from './query';
|
||||
import { ContactsFilterContext } from '@/context/contacts-filter';
|
||||
import { ContactsContext } from '@/context/contacts-context';
|
||||
import { sift } from 'radash';
|
||||
import { use, useEffect, useMemo } from 'react';
|
||||
|
||||
export function useCustomerContacts() {
|
||||
const { filter, setFilter } = use(ContactsFilterContext);
|
||||
const { filter, setFilter } = use(ContactsContext);
|
||||
|
||||
const {
|
||||
data: clientsData,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user