@q2devel/q2-storybook 1.0.162 → 1.0.164
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/Auth.types.d.ts +5 -5
- package/dist/auth/components/AuthenticatedFactory.d.ts +2 -2
- package/dist/auth/components/AuthenticatedFactory.js +4 -4
- package/dist/auth/components/AuthenticatedFactory.types.d.ts +2 -2
- package/dist/auth/config/Config.d.ts +1 -1
- package/dist/auth/config/Config.js +12 -12
- package/dist/auth/config/config.types.d.ts +3 -3
- package/dist/auth/context/AuthContextFactory.d.ts +1 -1
- package/dist/auth/context/AuthContextFactory.js +2 -2
- package/dist/auth/hooks/useCurrentUserHookFactory.d.ts +1 -1
- package/dist/auth/hooks/useCurrentUserHookFactory.js +2 -2
- package/dist/auth/hooks/useCurrentUserUpdateHookFactory.d.ts +2 -2
- package/dist/auth/hooks/useCurrentUserUpdateHookFactory.js +6 -6
- package/dist/auth/hooks/useCurrentUserUpdatePasswordHookFactory.d.ts +2 -2
- package/dist/auth/hooks/useCurrentUserUpdatePasswordHookFactory.js +5 -5
- package/dist/auth/hooks/useForgotPasswordHookFactory.d.ts +2 -2
- package/dist/auth/hooks/useForgotPasswordHookFactory.js +5 -5
- package/dist/auth/hooks/useResetPasswordHookFactory.d.ts +2 -2
- package/dist/auth/hooks/useResetPasswordHookFactory.js +5 -5
- package/dist/auth/hooks/useSignInHookFactory.d.ts +2 -2
- package/dist/auth/hooks/useSignInHookFactory.js +5 -5
- package/dist/auth/hooks/useSignOutHookFactory.d.ts +1 -1
- package/dist/auth/hooks/useSignOutHookFactory.js +5 -5
- package/dist/auth/hooks/useSignUpHookFactory.d.ts +2 -2
- package/dist/auth/hooks/useSignUpHookFactory.js +5 -5
- package/dist/auth/index.d.ts +3 -3
- package/dist/auth/index.js +14 -14
- package/dist/auth/provider/AuthContextProviderFactory.d.ts +1 -1
- package/dist/auth/provider/AuthContextProviderFactory.js +11 -4
- package/dist/auth/service/AuthService.d.ts +4 -4
- package/dist/auth/service/AuthService.js +13 -11
- package/dist/auth/service/index.d.ts +2 -2
- package/dist/auth/service/index.js +2 -2
- package/dist/auth/utils/Storage.d.ts +2 -2
- package/dist/auth/utils/Storage.js +2 -2
- package/dist/components/Base/badge/Badge.d.ts +1 -1
- package/dist/components/Base/badge/Badge.js +2 -2
- package/dist/components/Base/blog-builder/BlogBuilder.d.ts +3 -3
- package/dist/components/Base/blog-builder/BlogBuilder.js +23 -23
- package/dist/components/Base/blog-builder/carousel-paragraph/CarouselParagraph.d.ts +1 -1
- package/dist/components/Base/blog-builder/carousel-paragraph/CarouselParagraph.js +1 -1
- package/dist/components/Base/blog-builder/text-and-media-paragraph/TextAndMediaParagraph.d.ts +1 -1
- package/dist/components/Base/blog-builder/text-and-media-paragraph/TextAndMediaParagraph.js +9 -9
- package/dist/components/Base/blog-builder/text-paragraph/TextParagraph.js +1 -1
- package/dist/components/Base/blog-builder/video-paragraph/VideoParagraph.js +2 -2
- package/dist/components/Base/button/AddToCart.d.ts +1 -1
- package/dist/components/Base/button/AddToCart.js +3 -3
- package/dist/components/Base/button/Button.d.ts +4 -4
- package/dist/components/Base/button/Button.js +16 -16
- package/dist/components/Base/heading/Heading.d.ts +1 -1
- package/dist/components/Base/heading/Heading.js +9 -9
- package/dist/components/Base/image-gallery-modal/ImageGalleryModal.js +11 -11
- package/dist/components/Base/modal/Modal.d.ts +1 -1
- package/dist/components/Base/modal/Modal.js +7 -6
- package/dist/components/Base/price/Price.d.ts +1 -1
- package/dist/components/Base/price/Price.js +3 -3
- package/dist/components/Base/select/Select.d.ts +2 -2
- package/dist/components/Base/select/Select.js +18 -18
- package/dist/components/Base/spinner/Spinner.d.ts +3 -3
- package/dist/components/Base/spinner/Spinner.js +7 -7
- package/dist/components/Base/switch/Switch.js +20 -14
- package/dist/components/Base/tooltip/Tooltip.d.ts +5 -5
- package/dist/components/Base/tooltip/Tooltip.js +43 -42
- package/dist/components/Ecommerce/basket-dialog/BasketDialog.d.ts +3 -3
- package/dist/components/Ecommerce/basket-dialog/BasketDialog.js +40 -27
- package/dist/components/Ecommerce/basket-overview/BasketOverview.d.ts +2 -2
- package/dist/components/Ecommerce/basket-overview/BasketOverview.js +20 -17
- package/dist/components/Ecommerce/category-tree/CategoryTree.d.ts +1 -1
- package/dist/components/Ecommerce/category-tree/CategoryTree.js +11 -11
- package/dist/components/Ecommerce/instructions-list/Instruction.js +4 -4
- package/dist/components/Ecommerce/instructions-list/InstructionsList.js +1 -1
- package/dist/components/Ecommerce/product-card/ProductCard.d.ts +14 -14
- package/dist/components/Ecommerce/product-card/ProductCard.js +74 -64
- package/dist/components/Ecommerce/product-detail/ProductDetail.d.ts +4 -4
- package/dist/components/Ecommerce/product-detail/ProductDetail.js +173 -112
- package/dist/components/Ecommerce/product-detail/ProductDetailGallery.d.ts +1 -1
- package/dist/components/Ecommerce/product-detail/ProductDetailGallery.js +5 -5
- package/dist/components/Ecommerce/progress-stepper/ProgressStepper.d.ts +3 -3
- package/dist/components/Ecommerce/progress-stepper/ProgressStepper.js +21 -15
- package/dist/components/Ecommerce/wishlist/DeleteButton.d.ts +2 -2
- package/dist/components/Ecommerce/wishlist/DeleteButton.js +17 -15
- package/dist/components/Ecommerce/wishlist/LikeButton.d.ts +1 -1
- package/dist/components/Ecommerce/wishlist/LikeButton.js +20 -14
- package/dist/components/Ecommerce/wishlist/WishlistDropdown.js +9 -9
- package/dist/components/Forms/checkbox/Checkbox.d.ts +5 -5
- package/dist/components/Forms/checkbox/Checkbox.js +33 -32
- package/dist/components/Forms/checkbox/CheckboxGroup.d.ts +2 -2
- package/dist/components/Forms/checkbox/CheckboxGroup.js +17 -14
- package/dist/components/Forms/checkbox/NumCheckbox.d.ts +5 -5
- package/dist/components/Forms/checkbox/NumCheckbox.js +2 -2
- package/dist/components/Forms/contact-form/ContactForm.d.ts +1 -1
- package/dist/components/Forms/contact-form/ContactForm.js +79 -71
- package/dist/components/Forms/dropdown/Dropdown.js +8 -6
- package/dist/components/Forms/select-field/SelectField.d.ts +8 -8
- package/dist/components/Forms/select-field/SelectField.js +48 -47
- package/dist/components/Forms/select-field/SelectFieldOption.d.ts +1 -1
- package/dist/components/Forms/select-field/SelectFieldOption.js +1 -1
- package/dist/components/Forms/text-area/TextArea.d.ts +3 -3
- package/dist/components/Forms/text-area/TextArea.js +13 -13
- package/dist/components/Forms/text-field/TextField.d.ts +2 -2
- package/dist/components/Forms/text-field/TextField.js +50 -50
- package/dist/components/Forms/text-field/TextField.types.d.ts +7 -7
- package/dist/components/MIKS/ScheduleDetail/ScheduleDetail.js +7 -7
- package/dist/components/MIKS/date-carousel/DateCarousel.js +37 -35
- package/dist/components/MIKS/event-card/EventCard.js +10 -10
- package/dist/components/MIKS/filters/FilterContainer.d.ts +1 -1
- package/dist/components/MIKS/filters/FilterContainer.js +2 -2
- package/dist/components/MIKS/filters/FilterGrid.d.ts +1 -1
- package/dist/components/MIKS/filters/FilterGrid.js +7 -7
- package/dist/components/MIKS/filters/FilterType.js +18 -18
- package/dist/components/MIKS/filters/FilterWhen.js +35 -26
- package/dist/components/MIKS/filters/FilterWhere.js +15 -15
- package/dist/components/MIKS/filters/index.d.ts +7 -7
- package/dist/components/MIKS/filters/index.js +6 -6
- package/dist/components/MIKS/filters/useFilters.d.ts +1 -1
- package/dist/components/MIKS/filters/useFilters.js +1 -1
- package/dist/components/MIKS/footer/Footer.d.ts +1 -1
- package/dist/components/MIKS/footer/Footer.js +15 -15
- package/dist/components/MIKS/index.d.ts +21 -21
- package/dist/components/MIKS/index.js +8 -8
- package/dist/components/MIKS/movie-detail/MovieDetail.js +10 -10
- package/dist/components/MIKS/navbar/NavBar.d.ts +1 -1
- package/dist/components/MIKS/navbar/NavBar.js +3 -3
- package/dist/components/MIKS/theatre-event/TheatreEvent.js +5 -5
- package/dist/components/Tables/apartment-price-list/ApartmentPriceList.d.ts +1 -1
- package/dist/components/Tables/apartment-price-list/ApartmentPriceList.js +4 -1
- package/dist/components/Web/banner/Banner.d.ts +12 -12
- package/dist/components/Web/banner/Banner.js +76 -72
- package/dist/components/Web/blog/BlogCard.d.ts +5 -5
- package/dist/components/Web/blog/BlogCard.js +46 -34
- package/dist/components/Web/breadcrumb/Breadcrumb.d.ts +1 -1
- package/dist/components/Web/breadcrumb/Breadcrumb.js +5 -5
- package/dist/components/Web/dynamic-grid/DynamicLayout.d.ts +1 -1
- package/dist/components/Web/dynamic-grid/DynamicLayout.js +46 -46
- package/dist/components/Web/faq/FaqSection.d.ts +2 -2
- package/dist/components/Web/faq/FaqSection.js +12 -12
- package/dist/components/Web/footer/Footer.d.ts +1 -1
- package/dist/components/Web/footer/Footer.js +1 -1
- package/dist/components/Web/footer/FooterProps.d.ts +1 -1
- package/dist/components/Web/nav-bar/NavBar.d.ts +1 -1
- package/dist/components/Web/nav-bar/NavBar.js +6 -6
- package/dist/components/Web/stats-card/StatsCard.js +5 -5
- package/dist/components/Web/tabs/HorizontalTab.d.ts +1 -1
- package/dist/components/Web/tabs/HorizontalTab.js +8 -8
- package/dist/components/Web/text-with-image/ImageWithText.d.ts +1 -1
- package/dist/components/Web/text-with-image/ImageWithText.js +3 -3
- package/dist/components/Web/web-section/MediaSlider.js +22 -22
- package/dist/components/Web/web-section/WebSection.d.ts +3 -3
- package/dist/components/Web/web-section/WebSection.js +20 -20
- package/dist/components/icon/CloseIcon.d.ts +1 -1
- package/dist/components/icon/InfoIcon.d.ts +1 -1
- package/dist/components/icon/InfoIcon.js +1 -1
- package/dist/components/label/Label.js +2 -2
- package/dist/i18n/navigation.d.ts +2 -2
- package/dist/i18n/navigation.js +1 -1
- package/dist/index.d.ts +62 -62
- package/dist/index.js +54 -54
- package/dist/server/grid-endpoint.js +11 -11
- package/dist/utils/Helper.js +2 -2
- package/dist/utils/StyleHelper.d.ts +1 -1
- package/dist/utils/StyleHelper.js +2 -2
- package/dist/utils/generalHelperFunction.d.ts +3 -3
- package/dist/utils/generalHelperFunction.js +52 -52
- package/package.json +81 -81
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AxiosInstance } from
|
|
2
|
-
import { Context, PropsWithChildren } from
|
|
3
|
-
import { AccessToken, DeepNonRequired } from
|
|
4
|
-
import { AuthenticationSettings } from
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { Context, PropsWithChildren } from 'react';
|
|
3
|
+
import { AccessToken, DeepNonRequired } from './types';
|
|
4
|
+
import { AuthenticationSettings } from './config/config.types';
|
|
5
5
|
export type AuthContextType<UserType> = Context<AuthContextState<UserType>>;
|
|
6
|
-
export type LoadingType =
|
|
6
|
+
export type LoadingType = 'SIGN_IN' | 'SIGN_UP' | 'SIGN_OUT' | 'FORGOT_PASSWORD' | 'RESET_PASSWORD' | 'CURRENT_USER' | 'UPDATE_CURRENT_USER' | 'UPDATE_CURRENT_USER_PASSWORD';
|
|
7
7
|
export type TokenStorage = {
|
|
8
8
|
get: () => AccessToken | undefined;
|
|
9
9
|
set: (accessToken?: AccessToken) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthContextType } from
|
|
2
|
-
import { AuthenticatedProps } from
|
|
1
|
+
import { AuthContextType } from '../Auth.types';
|
|
2
|
+
import { AuthenticatedProps } from './AuthenticatedFactory.types';
|
|
3
3
|
declare const createAuthenticatedComponent: <UserType extends unknown>(AuthContext: AuthContextType<UserType>) => {
|
|
4
4
|
({ children, middleware }: AuthenticatedProps): import("react/jsx-runtime").JSX.Element | null;
|
|
5
5
|
displayName: string;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
// src/auth/components/AuthenticatedFactory.tsx
|
|
3
|
-
import { useContext } from
|
|
3
|
+
import { useContext } from 'react';
|
|
4
4
|
const createAuthenticatedComponent = (AuthContext) => {
|
|
5
5
|
const Authenticated = ({ children, middleware }) => {
|
|
6
6
|
const { isLogged, isReady } = useContext(AuthContext);
|
|
7
7
|
if (!isReady) {
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
10
|
-
if (middleware ===
|
|
10
|
+
if (middleware === 'only-logged' && !isLogged) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
|
-
if (middleware ===
|
|
13
|
+
if (middleware === 'only-guest' && isLogged) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
16
|
return _jsx(_Fragment, { children: children });
|
|
17
17
|
};
|
|
18
|
-
Authenticated.displayName =
|
|
18
|
+
Authenticated.displayName = 'Authenticated';
|
|
19
19
|
return Authenticated;
|
|
20
20
|
};
|
|
21
21
|
export default createAuthenticatedComponent;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Defaultní konfigurace
|
|
2
2
|
const config = {
|
|
3
|
-
tokenStorageType:
|
|
4
|
-
tokenStorageKey:
|
|
3
|
+
tokenStorageType: 'localStorage',
|
|
4
|
+
tokenStorageKey: 'auth-token',
|
|
5
5
|
logoutWhenFailedLoadUser: true,
|
|
6
6
|
getDataFromRequest: (data) => data.data,
|
|
7
7
|
getTokenFromRequest: (data) => data.token,
|
|
8
|
-
signInRoute:
|
|
9
|
-
defaultRequestType:
|
|
10
|
-
signOutRoute:
|
|
11
|
-
signUpRoute:
|
|
12
|
-
currentUserRoute:
|
|
13
|
-
currentUserUpdateRoute:
|
|
14
|
-
currentUserChangePasswordRoute:
|
|
15
|
-
currentUserChangeAvatarRoute:
|
|
16
|
-
forgotPasswordRoute:
|
|
17
|
-
resetPasswordRoute:
|
|
8
|
+
signInRoute: '/api/auth/login',
|
|
9
|
+
defaultRequestType: 'json',
|
|
10
|
+
signOutRoute: '/api/auth/logout',
|
|
11
|
+
signUpRoute: '/api/auth/register',
|
|
12
|
+
currentUserRoute: '/api/auth/user',
|
|
13
|
+
currentUserUpdateRoute: '/api/auth/user',
|
|
14
|
+
currentUserChangePasswordRoute: '/api/auth/user/password',
|
|
15
|
+
currentUserChangeAvatarRoute: '/api/auth/user/avatar',
|
|
16
|
+
forgotPasswordRoute: '/api/auth/forgot-password',
|
|
17
|
+
resetPasswordRoute: '/api/auth/reset-password',
|
|
18
18
|
};
|
|
19
19
|
export default config;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AccessToken, TokenStorageProvider } from
|
|
2
|
-
export type TokenStorageType =
|
|
3
|
-
export type RequestDataType =
|
|
1
|
+
import { AccessToken, TokenStorageProvider } from '../types';
|
|
2
|
+
export type TokenStorageType = 'localStorage' | 'cookie' | 'memory';
|
|
3
|
+
export type RequestDataType = 'json' | 'form-data';
|
|
4
4
|
export type AuthenticationSettings = {
|
|
5
5
|
tokenStorageType: TokenStorageType | TokenStorageProvider;
|
|
6
6
|
tokenStorageKey: string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useContext } from
|
|
1
|
+
import { useContext } from 'react';
|
|
2
2
|
const createUseCurrentUserHook = (AuthContext) => {
|
|
3
3
|
return () => {
|
|
4
4
|
const { currentUser, setCurrentUser, refetchCurrentUser, setAccessToken, loading, isLogged, isReady, } = useContext(AuthContext);
|
|
5
|
-
const isLoading = loading.includes(
|
|
5
|
+
const isLoading = loading.includes('CURRENT_USER');
|
|
6
6
|
return {
|
|
7
7
|
isLogged,
|
|
8
8
|
isReady,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthContextType } from
|
|
2
|
-
import { DefaultUpdateCurrentUserRequestData } from
|
|
1
|
+
import { AuthContextType } from '../Auth.types';
|
|
2
|
+
import { DefaultUpdateCurrentUserRequestData } from '../service';
|
|
3
3
|
declare const createUseCurrentUserUpdateHook: <UserType>(AuthContext: AuthContextType<UserType>) => <UpdateCurrentUserRequestData = DefaultUpdateCurrentUserRequestData>() => {
|
|
4
4
|
updateCurrentUser: (data: UpdateCurrentUserRequestData) => Promise<(UserType & {
|
|
5
5
|
token: import("..").AccessToken;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useContext, useCallback } from
|
|
2
|
-
import { updateCurrentUser } from
|
|
1
|
+
import { useContext, useCallback } from 'react';
|
|
2
|
+
import { updateCurrentUser } from '../service/AuthService';
|
|
3
3
|
const createUseCurrentUserUpdateHook = (AuthContext) => {
|
|
4
4
|
return () => {
|
|
5
|
-
const { axiosInstance, config, addLoading, removeLoading, setCurrentUser } = useContext(AuthContext);
|
|
5
|
+
const { axiosInstance, config, addLoading, removeLoading, setCurrentUser, } = useContext(AuthContext);
|
|
6
6
|
const loading = useContext(AuthContext).loading;
|
|
7
|
-
const isLoading = loading.includes(
|
|
7
|
+
const isLoading = loading.includes('UPDATE_CURRENT_USER');
|
|
8
8
|
const updateCallback = useCallback(async (data) => {
|
|
9
9
|
try {
|
|
10
|
-
addLoading(
|
|
10
|
+
addLoading('UPDATE_CURRENT_USER');
|
|
11
11
|
const response = await updateCurrentUser(axiosInstance, config, data);
|
|
12
12
|
setCurrentUser(response);
|
|
13
13
|
return response;
|
|
@@ -16,7 +16,7 @@ const createUseCurrentUserUpdateHook = (AuthContext) => {
|
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
18
|
finally {
|
|
19
|
-
removeLoading(
|
|
19
|
+
removeLoading('UPDATE_CURRENT_USER');
|
|
20
20
|
}
|
|
21
21
|
}, [axiosInstance, config, addLoading, removeLoading, setCurrentUser]);
|
|
22
22
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthContextType } from
|
|
2
|
-
import { DefaultUpdateCurrentUserPasswordRequestData } from
|
|
1
|
+
import { AuthContextType } from '../Auth.types';
|
|
2
|
+
import { DefaultUpdateCurrentUserPasswordRequestData } from '../service';
|
|
3
3
|
declare const createUseCurrentUserUpdatePasswordHook: <UserType>(AuthContext: AuthContextType<UserType>) => <UpdateCurrentUserPasswordRequestData = DefaultUpdateCurrentUserPasswordRequestData>() => {
|
|
4
4
|
updateCurrentUserPassword: (data: UpdateCurrentUserPasswordRequestData) => Promise<import("..").MakeUserWithAccessToken<UserType> | undefined>;
|
|
5
5
|
isLoading: boolean;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useContext, useCallback } from
|
|
2
|
-
import { updateCurrentUserPassword } from
|
|
1
|
+
import { useContext, useCallback } from 'react';
|
|
2
|
+
import { updateCurrentUserPassword } from '../service/AuthService';
|
|
3
3
|
const createUseCurrentUserUpdatePasswordHook = (AuthContext) => {
|
|
4
4
|
return () => {
|
|
5
5
|
const { axiosInstance, config, addLoading, removeLoading, setAccessToken, setCurrentUser, } = useContext(AuthContext);
|
|
6
6
|
const loading = useContext(AuthContext).loading;
|
|
7
|
-
const isLoading = loading.includes(
|
|
7
|
+
const isLoading = loading.includes('UPDATE_CURRENT_USER_PASSWORD');
|
|
8
8
|
const updatePasswordCallback = useCallback(async (data) => {
|
|
9
9
|
try {
|
|
10
|
-
addLoading(
|
|
10
|
+
addLoading('UPDATE_CURRENT_USER_PASSWORD');
|
|
11
11
|
const response = await updateCurrentUserPassword(axiosInstance, config, data);
|
|
12
12
|
if (response.token) {
|
|
13
13
|
setAccessToken(response.token);
|
|
@@ -19,7 +19,7 @@ const createUseCurrentUserUpdatePasswordHook = (AuthContext) => {
|
|
|
19
19
|
return undefined;
|
|
20
20
|
}
|
|
21
21
|
finally {
|
|
22
|
-
removeLoading(
|
|
22
|
+
removeLoading('UPDATE_CURRENT_USER_PASSWORD');
|
|
23
23
|
}
|
|
24
24
|
}, [
|
|
25
25
|
axiosInstance,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthContextType } from
|
|
2
|
-
import { DefaultForgotPasswordRequestData } from
|
|
1
|
+
import { AuthContextType } from '../Auth.types';
|
|
2
|
+
import { DefaultForgotPasswordRequestData } from '../service';
|
|
3
3
|
declare const createUseForgotPasswordHook: <UserType>(AuthContext: AuthContextType<UserType>) => <ForgotPasswordRequestData = DefaultForgotPasswordRequestData>() => {
|
|
4
4
|
forgotPassword: (data: ForgotPasswordRequestData) => Promise<any>;
|
|
5
5
|
isLoading: boolean;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { useContext, useCallback } from
|
|
2
|
-
import { forgotPassword } from
|
|
1
|
+
import { useContext, useCallback } from 'react';
|
|
2
|
+
import { forgotPassword } from '../service/AuthService';
|
|
3
3
|
const createUseForgotPasswordHook = (AuthContext) => {
|
|
4
4
|
return () => {
|
|
5
5
|
const { axiosInstance, config, addLoading, removeLoading } = useContext(AuthContext);
|
|
6
6
|
const loading = useContext(AuthContext).loading;
|
|
7
|
-
const isLoading = loading.includes(
|
|
7
|
+
const isLoading = loading.includes('FORGOT_PASSWORD');
|
|
8
8
|
const forgotPasswordCallback = useCallback(async (data) => {
|
|
9
9
|
try {
|
|
10
|
-
addLoading(
|
|
10
|
+
addLoading('FORGOT_PASSWORD');
|
|
11
11
|
return await forgotPassword(axiosInstance, config, data);
|
|
12
12
|
}
|
|
13
13
|
catch (e) {
|
|
14
14
|
return undefined;
|
|
15
15
|
}
|
|
16
16
|
finally {
|
|
17
|
-
removeLoading(
|
|
17
|
+
removeLoading('FORGOT_PASSWORD');
|
|
18
18
|
}
|
|
19
19
|
}, [axiosInstance, config, addLoading, removeLoading]);
|
|
20
20
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthContextType } from
|
|
2
|
-
import { DefaultResetPasswordRequestData } from
|
|
1
|
+
import { AuthContextType } from '../Auth.types';
|
|
2
|
+
import { DefaultResetPasswordRequestData } from '../service';
|
|
3
3
|
declare const createUseResetPasswordHook: <UserType>(AuthContext: AuthContextType<UserType>) => <PasswordResetRequestData = DefaultResetPasswordRequestData>() => {
|
|
4
4
|
resetPassword: (data: PasswordResetRequestData) => Promise<import("..").MakeUserWithAccessToken<UserType> | undefined>;
|
|
5
5
|
isLoading: boolean;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useContext, useCallback } from
|
|
2
|
-
import { resetPassword } from
|
|
1
|
+
import { useContext, useCallback } from 'react';
|
|
2
|
+
import { resetPassword } from '../service/AuthService';
|
|
3
3
|
const createUseResetPasswordHook = (AuthContext) => {
|
|
4
4
|
return () => {
|
|
5
5
|
const { axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading, } = useContext(AuthContext);
|
|
6
6
|
const loading = useContext(AuthContext).loading;
|
|
7
|
-
const isLoading = loading.includes(
|
|
7
|
+
const isLoading = loading.includes('RESET_PASSWORD');
|
|
8
8
|
const resetPasswordCallback = useCallback(async (data) => {
|
|
9
9
|
try {
|
|
10
|
-
addLoading(
|
|
10
|
+
addLoading('RESET_PASSWORD');
|
|
11
11
|
const response = await resetPassword(axiosInstance, config, data);
|
|
12
12
|
setAccessToken(response.token);
|
|
13
13
|
setCurrentUser(response);
|
|
@@ -17,7 +17,7 @@ const createUseResetPasswordHook = (AuthContext) => {
|
|
|
17
17
|
return undefined;
|
|
18
18
|
}
|
|
19
19
|
finally {
|
|
20
|
-
removeLoading(
|
|
20
|
+
removeLoading('RESET_PASSWORD');
|
|
21
21
|
}
|
|
22
22
|
}, [
|
|
23
23
|
axiosInstance,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthContextType } from
|
|
2
|
-
import { DefaultSignInRequestData } from
|
|
1
|
+
import { AuthContextType } from '../Auth.types';
|
|
2
|
+
import { DefaultSignInRequestData } from '../service';
|
|
3
3
|
declare const createUseSignInHook: <UserType>(AuthContext: AuthContextType<UserType>) => <SignInRequestData = DefaultSignInRequestData>() => {
|
|
4
4
|
signIn: (data: SignInRequestData, customApiUrl?: string) => Promise<import("..").MakeUserWithAccessToken<UserType> | undefined>;
|
|
5
5
|
isLoading: boolean;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/auth/hooks/UseSignInHookFactory.tsx
|
|
2
|
-
import { useContext, useCallback } from
|
|
3
|
-
import { signIn } from
|
|
2
|
+
import { useContext, useCallback } from 'react';
|
|
3
|
+
import { signIn } from '../service/AuthService';
|
|
4
4
|
const createUseSignInHook = (AuthContext) => {
|
|
5
5
|
return () => {
|
|
6
6
|
const { axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading, } = useContext(AuthContext);
|
|
7
7
|
const loading = useContext(AuthContext).loading;
|
|
8
|
-
const isLoading = loading.includes(
|
|
8
|
+
const isLoading = loading.includes('SIGN_IN');
|
|
9
9
|
const signInCallback = useCallback(async (data, customApiUrl) => {
|
|
10
10
|
try {
|
|
11
|
-
addLoading(
|
|
11
|
+
addLoading('SIGN_IN');
|
|
12
12
|
const response = await signIn(axiosInstance, config, data);
|
|
13
13
|
setAccessToken(response.token);
|
|
14
14
|
setCurrentUser(response);
|
|
@@ -18,7 +18,7 @@ const createUseSignInHook = (AuthContext) => {
|
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
finally {
|
|
21
|
-
removeLoading(
|
|
21
|
+
removeLoading('SIGN_IN');
|
|
22
22
|
}
|
|
23
23
|
}, [
|
|
24
24
|
axiosInstance,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/auth/hooks/UseSignOutHookFactory.tsx
|
|
2
|
-
import { useContext, useCallback } from
|
|
3
|
-
import { signOut } from
|
|
2
|
+
import { useContext, useCallback } from 'react';
|
|
3
|
+
import { signOut } from '../service/AuthService';
|
|
4
4
|
const createUseSignOutHook = (AuthContext) => {
|
|
5
5
|
return () => {
|
|
6
6
|
const { axiosInstance, config, destroyAccessToken, setCurrentUser, addLoading, removeLoading, } = useContext(AuthContext);
|
|
7
7
|
const loading = useContext(AuthContext).loading;
|
|
8
|
-
const isLoading = loading.includes(
|
|
8
|
+
const isLoading = loading.includes('SIGN_OUT');
|
|
9
9
|
const signOutCallback = useCallback(async () => {
|
|
10
10
|
try {
|
|
11
|
-
addLoading(
|
|
11
|
+
addLoading('SIGN_OUT');
|
|
12
12
|
const response = await signOut(axiosInstance, config);
|
|
13
13
|
destroyAccessToken();
|
|
14
14
|
setCurrentUser(undefined);
|
|
@@ -18,7 +18,7 @@ const createUseSignOutHook = (AuthContext) => {
|
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
finally {
|
|
21
|
-
removeLoading(
|
|
21
|
+
removeLoading('SIGN_OUT');
|
|
22
22
|
}
|
|
23
23
|
}, [
|
|
24
24
|
axiosInstance,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthContextType } from
|
|
2
|
-
import { DefaultSignUpRequestData } from
|
|
1
|
+
import { AuthContextType } from '../Auth.types';
|
|
2
|
+
import { DefaultSignUpRequestData } from '../service';
|
|
3
3
|
declare const createUseSignUpHook: <UserType>(AuthContext: AuthContextType<UserType>) => <SignUpRequestData = DefaultSignUpRequestData>() => {
|
|
4
4
|
signUp: (data: SignUpRequestData) => Promise<import("..").MakeUserWithAccessToken<UserType> | undefined>;
|
|
5
5
|
isLoading: boolean;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/auth/hooks/UseSignUpHookFactory.tsx
|
|
2
|
-
import { useContext, useCallback } from
|
|
3
|
-
import { signUp } from
|
|
2
|
+
import { useContext, useCallback } from 'react';
|
|
3
|
+
import { signUp } from '../service/AuthService';
|
|
4
4
|
const createUseSignUpHook = (AuthContext) => {
|
|
5
5
|
return () => {
|
|
6
6
|
const { axiosInstance, config, setAccessToken, setCurrentUser, addLoading, removeLoading, } = useContext(AuthContext);
|
|
7
7
|
const loading = useContext(AuthContext).loading;
|
|
8
|
-
const isLoading = loading.includes(
|
|
8
|
+
const isLoading = loading.includes('SIGN_UP');
|
|
9
9
|
const signUpCallback = useCallback(async (data) => {
|
|
10
10
|
try {
|
|
11
|
-
addLoading(
|
|
11
|
+
addLoading('SIGN_UP');
|
|
12
12
|
const response = await signUp(axiosInstance, config, data);
|
|
13
13
|
setAccessToken(response.token);
|
|
14
14
|
setCurrentUser(response);
|
|
@@ -18,7 +18,7 @@ const createUseSignUpHook = (AuthContext) => {
|
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
finally {
|
|
21
|
-
removeLoading(
|
|
21
|
+
removeLoading('SIGN_UP');
|
|
22
22
|
}
|
|
23
23
|
}, [
|
|
24
24
|
axiosInstance,
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -48,6 +48,6 @@ declare const createAuthentication: <UserType extends unknown>() => {
|
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
export default createAuthentication;
|
|
51
|
-
export * from
|
|
52
|
-
export * from
|
|
53
|
-
export * from
|
|
51
|
+
export * from './service/AuthService.types';
|
|
52
|
+
export * from './config/config.types';
|
|
53
|
+
export * from './types';
|
package/dist/auth/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import createAuthContext from
|
|
2
|
-
import createAuthContextProvider from
|
|
3
|
-
import createUseCurrentUserHook from
|
|
4
|
-
import createUseCurrentUserUpdateHook from
|
|
5
|
-
import createUseCurrentUserUpdatePasswordHook from
|
|
6
|
-
import createUseSignInHook from
|
|
7
|
-
import createUseSignOutHook from
|
|
8
|
-
import createUseSignUpHook from
|
|
9
|
-
import createUseForgotPasswordHook from
|
|
10
|
-
import createUseResetPasswordHook from
|
|
11
|
-
import createAuthenticatedComponent from
|
|
1
|
+
import createAuthContext from './context/AuthContextFactory';
|
|
2
|
+
import createAuthContextProvider from './provider/AuthContextProviderFactory';
|
|
3
|
+
import createUseCurrentUserHook from './hooks/useCurrentUserHookFactory';
|
|
4
|
+
import createUseCurrentUserUpdateHook from './hooks/useCurrentUserUpdateHookFactory';
|
|
5
|
+
import createUseCurrentUserUpdatePasswordHook from './hooks/useCurrentUserUpdatePasswordHookFactory';
|
|
6
|
+
import createUseSignInHook from './hooks/useSignInHookFactory';
|
|
7
|
+
import createUseSignOutHook from './hooks/useSignOutHookFactory';
|
|
8
|
+
import createUseSignUpHook from './hooks/useSignUpHookFactory';
|
|
9
|
+
import createUseForgotPasswordHook from './hooks/useForgotPasswordHookFactory';
|
|
10
|
+
import createUseResetPasswordHook from './hooks/useResetPasswordHookFactory';
|
|
11
|
+
import createAuthenticatedComponent from './components/AuthenticatedFactory';
|
|
12
12
|
const createAuthentication = () => {
|
|
13
13
|
const AuthContext = createAuthContext();
|
|
14
14
|
return {
|
|
@@ -25,6 +25,6 @@ const createAuthentication = () => {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
export default createAuthentication;
|
|
28
|
-
export * from
|
|
29
|
-
export * from
|
|
30
|
-
export * from
|
|
28
|
+
export * from './service/AuthService.types';
|
|
29
|
+
export * from './config/config.types';
|
|
30
|
+
export * from './types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthContextType, AuthProviderProps } from
|
|
1
|
+
import { AuthContextType, AuthProviderProps } from '../Auth.types';
|
|
2
2
|
declare const createAuthContextProvider: <UserType extends unknown>(AuthContext: AuthContextType<UserType>) => {
|
|
3
3
|
({ children, config, axiosInstance, initialAccessToken, initialCurrentUser, }: AuthProviderProps<UserType>): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
displayName: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useMemo, useState } from
|
|
3
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
4
4
|
const createAuthContextProvider = (AuthContext) => {
|
|
5
5
|
const Provider = ({ children, config, axiosInstance, initialAccessToken, initialCurrentUser, }) => {
|
|
6
6
|
const [accessToken, setAccessToken] = useState(initialAccessToken);
|
|
@@ -34,13 +34,20 @@ const createAuthContextProvider = (AuthContext) => {
|
|
|
34
34
|
addLoading,
|
|
35
35
|
removeLoading,
|
|
36
36
|
destroyAccessToken,
|
|
37
|
-
}), [
|
|
37
|
+
}), [
|
|
38
|
+
accessToken,
|
|
39
|
+
currentUser,
|
|
40
|
+
loading,
|
|
41
|
+
isLogged,
|
|
42
|
+
isReady,
|
|
43
|
+
axiosInstance,
|
|
44
|
+
]);
|
|
38
45
|
useEffect(() => {
|
|
39
46
|
setIsReady(true);
|
|
40
47
|
}, []);
|
|
41
48
|
return (_jsx(AuthContext.Provider, { value: authContextValue, children: children }));
|
|
42
49
|
};
|
|
43
|
-
Provider.displayName =
|
|
50
|
+
Provider.displayName = 'AuthContextProvider';
|
|
44
51
|
return Provider;
|
|
45
52
|
};
|
|
46
53
|
export default createAuthContextProvider;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AuthenticationSettings } from
|
|
2
|
-
import { AxiosInstance } from
|
|
3
|
-
import { DefaultForgotPasswordRequestData, DefaultResetPasswordRequestData, DefaultSignInRequestData, DefaultSignUpRequestData, DefaultUpdateCurrentUserPasswordRequestData, DefaultUpdateCurrentUserRequestData } from
|
|
4
|
-
import { MakeUserWithAccessToken } from
|
|
1
|
+
import { AuthenticationSettings } from '../config/config.types';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
import { DefaultForgotPasswordRequestData, DefaultResetPasswordRequestData, DefaultSignInRequestData, DefaultSignUpRequestData, DefaultUpdateCurrentUserPasswordRequestData, DefaultUpdateCurrentUserRequestData } from './AuthService.types';
|
|
4
|
+
import { MakeUserWithAccessToken } from '../types';
|
|
5
5
|
export declare const signIn: <UserType, SignInRequest = DefaultSignInRequestData>(axios: AxiosInstance, config: AuthenticationSettings, requestData: SignInRequest) => Promise<MakeUserWithAccessToken<UserType>>;
|
|
6
6
|
export declare const signOut: (axios: AxiosInstance, config: AuthenticationSettings) => Promise<any>;
|
|
7
7
|
export declare const signUp: <UserType, SignUpRequest = DefaultSignUpRequestData>(axios: AxiosInstance, config: AuthenticationSettings, requestData: SignUpRequest) => Promise<MakeUserWithAccessToken<UserType>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const signIn = async (axios, config, requestData) => {
|
|
2
2
|
const requestType = config.signInRouteRequestType || config.defaultRequestType;
|
|
3
|
-
const data = requestType ===
|
|
3
|
+
const data = requestType === 'json' ? requestData : createFormData(requestData);
|
|
4
4
|
const response = await axios.post(config.signInRoute, data);
|
|
5
5
|
const responseData = config.getDataFromRequest(response.data);
|
|
6
6
|
const token = config.getTokenFromRequest(response.data);
|
|
@@ -11,13 +11,13 @@ export const signIn = async (axios, config, requestData) => {
|
|
|
11
11
|
};
|
|
12
12
|
export const signOut = async (axios, config) => {
|
|
13
13
|
const requestType = config.signOutRouteRequestType || config.defaultRequestType;
|
|
14
|
-
const data = requestType ===
|
|
14
|
+
const data = requestType === 'json' ? {} : new FormData();
|
|
15
15
|
const response = await axios.post(config.signOutRoute, data);
|
|
16
16
|
return response.data;
|
|
17
17
|
};
|
|
18
18
|
export const signUp = async (axios, config, requestData) => {
|
|
19
19
|
const requestType = config.signUpRouteRequestType || config.defaultRequestType;
|
|
20
|
-
const data = requestType ===
|
|
20
|
+
const data = requestType === 'json' ? requestData : createFormData(requestData);
|
|
21
21
|
const response = await axios.post(config.signUpRoute, data);
|
|
22
22
|
const responseData = config.getDataFromRequest(response.data);
|
|
23
23
|
const token = config.getTokenFromRequest(response.data);
|
|
@@ -28,13 +28,13 @@ export const signUp = async (axios, config, requestData) => {
|
|
|
28
28
|
};
|
|
29
29
|
export const forgotPassword = async (axios, config, requestData) => {
|
|
30
30
|
const requestType = config.forgotPasswordRouteRequestDataType || config.defaultRequestType;
|
|
31
|
-
const data = requestType ===
|
|
31
|
+
const data = requestType === 'json' ? requestData : createFormData(requestData);
|
|
32
32
|
const response = await axios.post(config.forgotPasswordRoute, data);
|
|
33
33
|
return response.data;
|
|
34
34
|
};
|
|
35
35
|
export const resetPassword = async (axios, config, requestData) => {
|
|
36
36
|
const requestType = config.resetPasswordRouteRequestDataType || config.defaultRequestType;
|
|
37
|
-
const data = requestType ===
|
|
37
|
+
const data = requestType === 'json' ? requestData : createFormData(requestData);
|
|
38
38
|
const response = await axios.post(config.resetPasswordRoute, data);
|
|
39
39
|
const responseData = config.getDataFromRequest(response.data);
|
|
40
40
|
const token = config.getTokenFromRequest(response.data);
|
|
@@ -49,8 +49,9 @@ export const getCurrentUser = async (axios, config) => {
|
|
|
49
49
|
return responseData;
|
|
50
50
|
};
|
|
51
51
|
export const updateCurrentUser = async (axios, config, requestData) => {
|
|
52
|
-
const requestType = config.currentUserUpdateRouteRequestDataType ||
|
|
53
|
-
|
|
52
|
+
const requestType = config.currentUserUpdateRouteRequestDataType ||
|
|
53
|
+
config.defaultRequestType;
|
|
54
|
+
const data = requestType === 'json' ? requestData : createFormData(requestData);
|
|
54
55
|
const response = await axios.post(config.currentUserUpdateRoute, data);
|
|
55
56
|
const responseData = config.getDataFromRequest(response.data);
|
|
56
57
|
const token = config.getTokenFromRequest(response.data);
|
|
@@ -62,7 +63,7 @@ export const updateCurrentUser = async (axios, config, requestData) => {
|
|
|
62
63
|
export const updateCurrentUserPassword = async (axios, config, requestData) => {
|
|
63
64
|
const requestType = config.currentUserChangePasswordRouteRequestDataType ||
|
|
64
65
|
config.defaultRequestType;
|
|
65
|
-
const data = requestType ===
|
|
66
|
+
const data = requestType === 'json' ? requestData : createFormData(requestData);
|
|
66
67
|
const response = await axios.post(config.currentUserChangePasswordRoute, data);
|
|
67
68
|
const responseData = config.getDataFromRequest(response.data);
|
|
68
69
|
const token = config.getTokenFromRequest(response.data);
|
|
@@ -74,11 +75,11 @@ export const updateCurrentUserPassword = async (axios, config, requestData) => {
|
|
|
74
75
|
export const updateCurrentUserAvatar = async (axios, config, requestFile) => {
|
|
75
76
|
const formData = new FormData();
|
|
76
77
|
if (requestFile) {
|
|
77
|
-
formData.append(
|
|
78
|
+
formData.append('avatar', requestFile);
|
|
78
79
|
}
|
|
79
80
|
const response = await axios.post(config.currentUserChangeAvatarRoute, formData, {
|
|
80
81
|
headers: {
|
|
81
|
-
|
|
82
|
+
'Content-Type': 'multipart/form-data',
|
|
82
83
|
},
|
|
83
84
|
});
|
|
84
85
|
const responseData = config.getDataFromRequest(response.data);
|
|
@@ -91,7 +92,8 @@ function createFormData(data) {
|
|
|
91
92
|
if (data.hasOwnProperty(key)) {
|
|
92
93
|
// Pokud je hodnota null nebo undefined, nepřidávej ji do FormData
|
|
93
94
|
if (data[key] !== null && data[key] !== undefined) {
|
|
94
|
-
if (typeof data[key] ===
|
|
95
|
+
if (typeof data[key] === 'object' &&
|
|
96
|
+
!(data[key] instanceof File)) {
|
|
95
97
|
formData.append(key, JSON.stringify(data[key]));
|
|
96
98
|
}
|
|
97
99
|
else {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './AuthService.types';
|
|
2
|
+
export * from './AuthService';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// src/service/index.ts
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
2
|
+
export * from './AuthService.types';
|
|
3
|
+
export * from './AuthService';
|