Files
cal.diy/packages/platform/atoms/hooks/useAtomsContext.ts
T
0b03bcb90e feat: CalendarSettings atom (#16120)
* dumb components for calendar settings

* shadcn switch

* update exports

* update packages

* add calendar settings atom to examples app

* init calendar settings atom

* refactors

* fix import path

* export type for calendar switch props

* invalidate queries on deleting calendar credentials

* replace calendars list with calendar settings wrapper

* cleanup

* update styling

* refactors

* cleanup

* fix: missing key prop CalendarSettingsPlatformWrapper

* Label as client components

* Address client component build errors

* Move QueryCell out of packages/lib

* PR feedback

* more feedback

---------

Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Morgan <[email protected]>
Co-authored-by: Morgan Vernay <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
2024-08-13 21:51:29 +05:30

46 lines
1.1 KiB
TypeScript

"use client";
import { createContext, useContext } from "react";
import type { translationKeys, CalProviderLanguagesType } from "../cal-provider/CalProvider";
import type http from "../lib/http";
export interface IAtomsContextOptions {
refreshUrl?: string;
apiUrl: string;
}
export interface IAtomsContext {
clientId: string;
accessToken?: string;
options: IAtomsContextOptions;
error?: string;
getClient: () => typeof http | void;
refreshToken?: string;
isRefreshing?: boolean;
isAuth: boolean;
isValidClient: boolean;
isInit: boolean;
t: (key: string, values: Record<string, string | number | undefined | null>) => string;
i18n: {
language: CalProviderLanguagesType;
defaultLocale: CalProviderLanguagesType;
locales: CalProviderLanguagesType[];
exists: (key: translationKeys | string) => boolean;
};
organizationId: number;
}
export const AtomsContext = createContext({
clientId: "",
accessToken: "",
organizationId: 0,
options: { refreshUrl: "", apiUrl: "" },
error: "",
getClient: () => {
return;
},
} as IAtomsContext);
export const useAtomsContext = () => useContext(AtomsContext);