Compare commits
No commits in common. "d77b4ffddb898d5e73d0fbcdd38230423896ee48" and "ea8bcae9dff1e6ade9908522dd4cddb074cddc3c" have entirely different histories.
d77b4ffddb
...
ea8bcae9df
@ -1,45 +0,0 @@
|
|||||||
import AdminUserModel from '~/business-logic/generic/admin-user/common/data/model/adminUserModel';
|
|
||||||
import { HTTPPovider } from '~/driven/boundaries/http-boundary/httpBoundary';
|
|
||||||
import { HttpOptionsType } from '~/driven/boundaries/http-boundary/protocols';
|
|
||||||
import { apiUrls } from '~/driven/utils/configs/appConfig';
|
|
||||||
import {
|
|
||||||
ICreatePlaceLogicMaker,
|
|
||||||
createPlaceArguments,
|
|
||||||
} from '~/driving/application/core/places/create-place/model/submiCreatePlace';
|
|
||||||
|
|
||||||
const createPlacesDto = (newPlace: createPlaceArguments) => ({
|
|
||||||
place_type: newPlace.placeType,
|
|
||||||
parent_id: newPlace.parentId || null,
|
|
||||||
name: newPlace.placeName,
|
|
||||||
});
|
|
||||||
|
|
||||||
const createPlaceAdapter = (
|
|
||||||
userAdmin: AdminUserModel | null,
|
|
||||||
updateAccessToken: (newAccessToken: string) => void,
|
|
||||||
navigateToAuth: () => void,
|
|
||||||
): ICreatePlaceLogicMaker => {
|
|
||||||
const url = apiUrls.core.createPlace;
|
|
||||||
const httpHandler = async (newPlace: createPlaceArguments) => {
|
|
||||||
const httpProvider = new HTTPPovider(
|
|
||||||
{
|
|
||||||
accessToken: (userAdmin && userAdmin?.adminUserData.accessToken) || null,
|
|
||||||
refreshToken: (userAdmin && userAdmin?.adminUserData.refreshToken) || null,
|
|
||||||
},
|
|
||||||
updateAccessToken,
|
|
||||||
navigateToAuth,
|
|
||||||
);
|
|
||||||
const dto = createPlacesDto(newPlace);
|
|
||||||
const options: HttpOptionsType = {
|
|
||||||
url,
|
|
||||||
method: 'POST',
|
|
||||||
data: dto,
|
|
||||||
};
|
|
||||||
|
|
||||||
return await httpProvider.request<string>(options);
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
httpHandler,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default createPlaceAdapter;
|
|
@ -46,6 +46,7 @@ export class HTTPPovider {
|
|||||||
async request<R>(customOptions: HttpOptionsType) {
|
async request<R>(customOptions: HttpOptionsType) {
|
||||||
const axiosInstance = this.handleRequestInterceptor();
|
const axiosInstance = this.handleRequestInterceptor();
|
||||||
this.responseIncepter(axiosInstance);
|
this.responseIncepter(axiosInstance);
|
||||||
|
|
||||||
const response = await axiosInstance<ApiGlobalResponseObject<R>>(customOptions);
|
const response = await axiosInstance<ApiGlobalResponseObject<R>>(customOptions);
|
||||||
if (!response) throw new Error(staticMessages.service.errors[500]);
|
if (!response) throw new Error(staticMessages.service.errors[500]);
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ export const apiUrls = {
|
|||||||
createUserAccount: `${baseApiUrl}${ENVs.apiCreateUserAccount}`,
|
createUserAccount: `${baseApiUrl}${ENVs.apiCreateUserAccount}`,
|
||||||
createUserProfile: `${baseApiUrl}${ENVs.apiCreateUserProfile}`,
|
createUserProfile: `${baseApiUrl}${ENVs.apiCreateUserProfile}`,
|
||||||
createMember: `${baseApiUrl}${ENVs.apiCreateMember}`,
|
createMember: `${baseApiUrl}${ENVs.apiCreateMember}`,
|
||||||
createPlace: `${baseApiUrl}${ENVs.apiCreatePlace}`,
|
|
||||||
},
|
},
|
||||||
generic: {
|
generic: {
|
||||||
authPhonenumber: `${ENVs.apiAuthOrigin}${ENVs.apiAuthPhonenumber}`,
|
authPhonenumber: `${ENVs.apiAuthOrigin}${ENVs.apiAuthPhonenumber}`,
|
||||||
|
@ -10,5 +10,4 @@ export const ENVs = {
|
|||||||
apiQr: process.env.VITE_API_QR,
|
apiQr: process.env.VITE_API_QR,
|
||||||
apiCreateUserProfile: process.env.VITE_API_USERS_PROFILE,
|
apiCreateUserProfile: process.env.VITE_API_USERS_PROFILE,
|
||||||
apiCreateMember: process.env.VITE_API_CREATE_MEMBER,
|
apiCreateMember: process.env.VITE_API_CREATE_MEMBER,
|
||||||
apiCreatePlace: process.env.VITE_API_PLACES,
|
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,6 @@ export const staticMessages = {
|
|||||||
input: 'please fill all inputs correctly',
|
input: 'please fill all inputs correctly',
|
||||||
phonenumber: 'please fill the valid number',
|
phonenumber: 'please fill the valid number',
|
||||||
otp: 'please fill the otp fields correctly',
|
otp: 'please fill the otp fields correctly',
|
||||||
inputPlace: 'place type and name of place is necessary',
|
|
||||||
},
|
},
|
||||||
users: 'Users',
|
users: 'Users',
|
||||||
submit: 'Submit',
|
submit: 'Submit',
|
||||||
@ -27,7 +26,6 @@ export const staticMessages = {
|
|||||||
success: {
|
success: {
|
||||||
createUser: 'user created successfully',
|
createUser: 'user created successfully',
|
||||||
createMember: 'member created successfully',
|
createMember: 'member created successfully',
|
||||||
createPlace: 'place created successfully',
|
|
||||||
},
|
},
|
||||||
and: 'and',
|
and: 'and',
|
||||||
canUseFor: 'can use for',
|
canUseFor: 'can use for',
|
||||||
@ -49,7 +47,7 @@ export const staticMessages = {
|
|||||||
},
|
},
|
||||||
service: {
|
service: {
|
||||||
errors: {
|
errors: {
|
||||||
500: 'there is a problem with connecting to the server please try again later!',
|
500: 'server not respond please try again later!',
|
||||||
401: 'Authentication error!',
|
401: 'Authentication error!',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import createPlaceAdapter from '~/driven/adapters/create-place-adapter/createPlaceAdapter';
|
|
||||||
import useGetNavigatorAndTokenUpdater from '~/driven/utils/helpers/hooks/getNavigatorAndAccessTokenUpdator';
|
|
||||||
import CreatePlaceView from '../view/CreatePlaceView';
|
import CreatePlaceView from '../view/CreatePlaceView';
|
||||||
import useCreatePlaceVm from '../viewmodel/createPlaceVM';
|
import useCreatePlaceVm from '../viewmodel/createPlaceVM';
|
||||||
import createPlaceModel from '../model/createPlaceModel';
|
import createPlaceModel from '../model/createPlaceModel';
|
||||||
|
|
||||||
export default function CreatePlace() {
|
export default function CreatePlace() {
|
||||||
const { accessTokenUpdateHandler, notLoginAuth, userData } = useGetNavigatorAndTokenUpdater();
|
const { inputOptions } = createPlaceModel();
|
||||||
const { user } = userData;
|
const { formStateData, inputStateHandlers, selectBoxOptions } = useCreatePlaceVm({
|
||||||
|
|
||||||
const createPlaceDrivenAdapter = createPlaceAdapter(user, accessTokenUpdateHandler, notLoginAuth);
|
|
||||||
const { inputOptions, createPlace } = createPlaceModel(createPlaceDrivenAdapter);
|
|
||||||
const { formStateData, inputStateHandlers, selectBoxOptions, handleSubmitCreatePlaceForm } = useCreatePlaceVm({
|
|
||||||
getInputOptions: inputOptions,
|
getInputOptions: inputOptions,
|
||||||
createPlaceModel: createPlace,
|
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<CreatePlaceView
|
<CreatePlaceView
|
||||||
handleSubmitCreatePlaceForm={handleSubmitCreatePlaceForm}
|
|
||||||
inputOptions={{
|
inputOptions={{
|
||||||
parentId: selectBoxOptions.parentIdsOptions,
|
parentId: selectBoxOptions.parentIdsOptions,
|
||||||
placeType: selectBoxOptions.placeTypesOptions,
|
placeType: selectBoxOptions.placeTypesOptions,
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
import { CreatePlaceType } from './protocols';
|
import { CreatePlaceType } from './protocols';
|
||||||
import getValidOptionsOfSelectBox from './getValidOptionsOfSelectBox';
|
import getValidOptionsOfSelectBox from './getValidOptionsOfSelectBox';
|
||||||
import createPlaceLogicMaker, { ICreatePlaceLogicMaker } from './submiCreatePlace';
|
|
||||||
|
|
||||||
type ICreatePlaceModel = ICreatePlaceLogicMaker;
|
const createPlaceModel = (): CreatePlaceType => {
|
||||||
|
|
||||||
const createPlaceModel = (depenedencies: ICreatePlaceModel): CreatePlaceType => {
|
|
||||||
const { getPlacesTypeOptionsOfSelectBox, getValidParentIdsOptionsOfSelectBox } = getValidOptionsOfSelectBox;
|
const { getPlacesTypeOptionsOfSelectBox, getValidParentIdsOptionsOfSelectBox } = getValidOptionsOfSelectBox;
|
||||||
|
|
||||||
const { createPlace } = createPlaceLogicMaker(depenedencies);
|
|
||||||
return {
|
return {
|
||||||
createPlace,
|
|
||||||
inputOptions: {
|
inputOptions: {
|
||||||
getPlaceType: getPlacesTypeOptionsOfSelectBox,
|
getPlaceType: getPlacesTypeOptionsOfSelectBox,
|
||||||
getParentIds: getValidParentIdsOptionsOfSelectBox,
|
getParentIds: getValidParentIdsOptionsOfSelectBox,
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
import createPlaceModel from './createPlaceModel';
|
|
||||||
|
|
||||||
export default createPlaceModel;
|
|
@ -1,9 +1,7 @@
|
|||||||
import PlacesModel from '~/business-logic/core/places/common/model/placesModel';
|
import PlacesModel from '~/business-logic/core/places/common/model/placesModel';
|
||||||
import { placeTypes } from '../view/protocol';
|
import { placeTypes } from '../view/protocol';
|
||||||
import { createPlaceArguments } from './submiCreatePlace';
|
|
||||||
|
|
||||||
export type CreatePlaceType = {
|
export type CreatePlaceType = {
|
||||||
createPlace: (placeData: createPlaceArguments) => Promise<string>;
|
|
||||||
inputOptions: {
|
inputOptions: {
|
||||||
getPlaceType: () => {
|
getPlaceType: () => {
|
||||||
value: placeTypes;
|
value: placeTypes;
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
import { placeTypes } from '../view/protocol';
|
|
||||||
|
|
||||||
export type createPlaceArguments = {
|
|
||||||
placeType: `${placeTypes}`;
|
|
||||||
placeName: string;
|
|
||||||
parentId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface ICreatePlaceLogicMaker {
|
|
||||||
httpHandler: (placeData: createPlaceArguments) => Promise<string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const createPlaceLogicMaker = (depenedencies: ICreatePlaceLogicMaker) => {
|
|
||||||
const { httpHandler } = depenedencies;
|
|
||||||
|
|
||||||
const createPlace = async (placeData: createPlaceArguments) => {
|
|
||||||
return await httpHandler(placeData);
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
createPlace,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default createPlaceLogicMaker;
|
|
@ -3,59 +3,49 @@ import SimpleInput from '~/driven/utils/components/inputs/simple-input/SimpleInp
|
|||||||
import InputBox from '~/driven/utils/components/inputs/select-box/InputBox';
|
import InputBox from '~/driven/utils/components/inputs/select-box/InputBox';
|
||||||
import { staticMessages } from '~/driven/utils/constants/staticMessages';
|
import { staticMessages } from '~/driven/utils/constants/staticMessages';
|
||||||
import PrimaryButton from '~/driven/utils/components/buttons/primary-button/PrimaryButton';
|
import PrimaryButton from '~/driven/utils/components/buttons/primary-button/PrimaryButton';
|
||||||
import Notification from '~/driven/utils/components/Notification/Notification';
|
|
||||||
import { ICreatePlaceProps } from './protocol';
|
import { ICreatePlaceProps } from './protocol';
|
||||||
|
|
||||||
export default function CreatePlaceView(props: ICreatePlaceProps) {
|
export default function CreatePlaceView(props: ICreatePlaceProps) {
|
||||||
const { formStateData, inputStateHandlers, inputOptions, handleSubmitCreatePlaceForm } = props;
|
const { formStateData, inputStateHandlers, inputOptions } = props;
|
||||||
const { formState, error, setError } = formStateData;
|
const { formState } = formStateData;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<form className='p-4 py-6 flex flex-wrap w-full gap-4'>
|
||||||
{Boolean(error.message) && (
|
<SimpleInput
|
||||||
<Notification
|
inputData={{
|
||||||
message={error.message}
|
name: staticMessages.global.PlaceName,
|
||||||
type={error.type}
|
title: staticMessages.global.PlaceName,
|
||||||
onCloseCallback={() => setError({ message: '', type: 'error' })}
|
}}
|
||||||
/>
|
stateHanlder={{
|
||||||
)}
|
state: formState.placeName,
|
||||||
<form onSubmit={handleSubmitCreatePlaceForm} className='p-4 py-6 flex flex-wrap w-full gap-4'>
|
setState: inputStateHandlers.name,
|
||||||
<SimpleInput
|
}}
|
||||||
inputData={{
|
className='mb-4 w-[48%] px-2'
|
||||||
name: staticMessages.global.PlaceName,
|
/>
|
||||||
title: staticMessages.global.PlaceName,
|
<InputBox
|
||||||
}}
|
name={staticMessages.global.placeType}
|
||||||
stateHanlder={{
|
state={{
|
||||||
state: formState.placeName,
|
value: { value: formState.placeTypes, label: staticMessages.placeTypes[formState.placeTypes] },
|
||||||
setState: inputStateHandlers.name,
|
setValue: inputStateHandlers.placeType,
|
||||||
}}
|
options: inputOptions.placeType,
|
||||||
className='mb-4 w-[48%] px-2'
|
}}
|
||||||
/>
|
title={staticMessages.global.placeType}
|
||||||
<InputBox
|
className='mb-4 w-[48%] px-2 border-1 border-txt-medium text-txt-medium'
|
||||||
name={staticMessages.global.placeType}
|
/>
|
||||||
state={{
|
<InputBox
|
||||||
value: { value: formState.placeTypes, label: staticMessages.placeTypes[formState.placeTypes] },
|
name={staticMessages.global.placeParentId}
|
||||||
setValue: inputStateHandlers.placeType,
|
state={{
|
||||||
options: inputOptions.placeType,
|
value: { value: formState.parentId.value, label: formState.parentId.label },
|
||||||
}}
|
setValue: inputStateHandlers.parentId,
|
||||||
title={staticMessages.global.placeType}
|
options: inputOptions.parentId,
|
||||||
className='mb-4 w-[48%] px-2 border-1 border-txt-medium text-txt-medium'
|
isLoading: inputOptions.isParentIdLoading,
|
||||||
/>
|
}}
|
||||||
<InputBox
|
title={staticMessages.global.placeParentId}
|
||||||
name={staticMessages.global.placeParentId}
|
className='mb-4 w-[48%] px-2 border-1 border-txt-medium text-txt-medium'
|
||||||
state={{
|
/>
|
||||||
value: { value: formState.parentId.value, label: formState.parentId.label },
|
<div className='w-full'>
|
||||||
setValue: inputStateHandlers.parentId,
|
<PrimaryButton onClick={() => null} title={staticMessages.global.submit} />
|
||||||
options: inputOptions.parentId,
|
</div>
|
||||||
isLoading: inputOptions.isParentIdLoading,
|
</form>
|
||||||
}}
|
|
||||||
title={staticMessages.global.placeParentId}
|
|
||||||
className='mb-4 w-[48%] px-2 border-1 border-txt-medium text-txt-medium'
|
|
||||||
/>
|
|
||||||
<div className='w-full'>
|
|
||||||
<PrimaryButton onClick={() => null} title={staticMessages.global.submit} />
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,19 +19,8 @@ export type PlaceFormState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface ICreatePlaceProps {
|
export interface ICreatePlaceProps {
|
||||||
handleSubmitCreatePlaceForm: (e: React.FormEvent) => Promise<void>;
|
|
||||||
formStateData: {
|
formStateData: {
|
||||||
formState: PlaceFormState;
|
formState: PlaceFormState;
|
||||||
error: {
|
|
||||||
message: string;
|
|
||||||
type: 'error' | 'success';
|
|
||||||
};
|
|
||||||
setError: React.Dispatch<
|
|
||||||
React.SetStateAction<{
|
|
||||||
message: string;
|
|
||||||
type: 'error' | 'success';
|
|
||||||
}>
|
|
||||||
>;
|
|
||||||
setFormState: React.Dispatch<React.SetStateAction<PlaceFormState>>;
|
setFormState: React.Dispatch<React.SetStateAction<PlaceFormState>>;
|
||||||
};
|
};
|
||||||
inputStateHandlers: {
|
inputStateHandlers: {
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { AxiosError } from 'axios';
|
|
||||||
import { staticMessages } from '~/driven/utils/constants/staticMessages';
|
|
||||||
import useGetPlaceList from '../../common/hooks/useGetPlaceList';
|
import useGetPlaceList from '../../common/hooks/useGetPlaceList';
|
||||||
import { PlaceFormState, placeTypes } from '../view/protocol';
|
import { PlaceFormState, placeTypes } from '../view/protocol';
|
||||||
import { createPlaceArguments } from '../model/submiCreatePlace';
|
|
||||||
import { ICreatePlaceVm, initialPlaceFormState } from './protocols';
|
import { ICreatePlaceVm, initialPlaceFormState } from './protocols';
|
||||||
|
|
||||||
const onChangeInputStateHandlers = (setFormState: React.Dispatch<React.SetStateAction<PlaceFormState>>) => {
|
const onChangeInputStateHandlers = (setFormState: React.Dispatch<React.SetStateAction<PlaceFormState>>) => {
|
||||||
@ -28,40 +25,15 @@ const resetParentIdOnChangePlaceType = (setFormState: React.Dispatch<React.SetSt
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useCreatePlaceVm = (dependencies: ICreatePlaceVm) => {
|
const useCreatePlaceVm = (dependencies: ICreatePlaceVm) => {
|
||||||
const { getInputOptions, createPlaceModel } = dependencies;
|
const { getInputOptions } = dependencies;
|
||||||
const { getParentIds, getPlaceType } = getInputOptions;
|
const { getParentIds, getPlaceType } = getInputOptions;
|
||||||
const [formState, setFormState] = useState<PlaceFormState>(initialPlaceFormState);
|
const [formState, setFormState] = useState<PlaceFormState>(initialPlaceFormState);
|
||||||
const [error, setError] = useState<{ message: string; type: 'error' | 'success' }>({ message: '', type: 'error' });
|
|
||||||
|
|
||||||
const { handleNameSetState, handleParentIdSetState, handlePlaceTypeSetState } = useMemo(
|
const { handleNameSetState, handleParentIdSetState, handlePlaceTypeSetState } = useMemo(
|
||||||
() => onChangeInputStateHandlers(setFormState),
|
() => onChangeInputStateHandlers(setFormState),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSubmitCreatePlaceForm = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
try {
|
|
||||||
const { parentId, placeName, placeTypes: placeType } = formState;
|
|
||||||
if (!placeName || !placeName) throw new Error(staticMessages.global.errors.inputPlace);
|
|
||||||
const newPlaceData: createPlaceArguments = {
|
|
||||||
parentId: parentId.value,
|
|
||||||
placeName,
|
|
||||||
placeType,
|
|
||||||
};
|
|
||||||
const response = await createPlaceModel(newPlaceData);
|
|
||||||
if (!response) throw new Error(staticMessages.service.errors[500]);
|
|
||||||
setError({
|
|
||||||
message: staticMessages.global.success.createPlace,
|
|
||||||
type: 'success',
|
|
||||||
});
|
|
||||||
} catch (errorExc) {
|
|
||||||
if (errorExc instanceof AxiosError) {
|
|
||||||
setError({ message: errorExc.response?.data?.description, type: 'error' });
|
|
||||||
} else if (errorExc instanceof Error) {
|
|
||||||
setError({ message: errorExc.message, type: 'error' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
useEffect(() => resetParentIdOnChangePlaceType(setFormState), [formState.placeTypes]);
|
useEffect(() => resetParentIdOnChangePlaceType(setFormState), [formState.placeTypes]);
|
||||||
|
|
||||||
const getPlaceList = useCallback(() => useGetPlaceList()(), []);
|
const getPlaceList = useCallback(() => useGetPlaceList()(), []);
|
||||||
@ -74,11 +46,8 @@ const useCreatePlaceVm = (dependencies: ICreatePlaceVm) => {
|
|||||||
}, [formState.placeTypes, places]);
|
}, [formState.placeTypes, places]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handleSubmitCreatePlaceForm,
|
|
||||||
formStateData: {
|
formStateData: {
|
||||||
formState,
|
formState,
|
||||||
error,
|
|
||||||
setError,
|
|
||||||
setFormState,
|
setFormState,
|
||||||
},
|
},
|
||||||
inputStateHandlers: {
|
inputStateHandlers: {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { CreatePlaceType } from '../model/protocols';
|
import { CreatePlaceType } from '../model/protocols';
|
||||||
import { createPlaceArguments } from '../model/submiCreatePlace';
|
|
||||||
import { PlaceFormState, placeTypes } from '../view/protocol';
|
import { PlaceFormState, placeTypes } from '../view/protocol';
|
||||||
|
|
||||||
export const initialPlaceFormState: PlaceFormState = {
|
export const initialPlaceFormState: PlaceFormState = {
|
||||||
@ -10,5 +9,4 @@ export const initialPlaceFormState: PlaceFormState = {
|
|||||||
|
|
||||||
export interface ICreatePlaceVm {
|
export interface ICreatePlaceVm {
|
||||||
getInputOptions: CreatePlaceType['inputOptions'];
|
getInputOptions: CreatePlaceType['inputOptions'];
|
||||||
createPlaceModel: (placeData: createPlaceArguments) => Promise<string>;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user