Skip to content

Commit

Permalink
Merge pull request #1003 from enatega/dispatchFlow
Browse files Browse the repository at this point in the history
handled all the changes in the enatega admin
  • Loading branch information
ufumerfarooq67 authored Feb 19, 2025
2 parents 062d814 + b795a04 commit b0eedd8
Show file tree
Hide file tree
Showing 18 changed files with 526 additions and 486 deletions.
81 changes: 49 additions & 32 deletions enatega-multivendor-admin/lib/api/graphql/queries/orders/index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
import { gql } from '@apollo/client';

export const GET_ACTIVE_ORDERS = gql`
query GetActiveOrders($restaurantId: ID) {
getActiveOrders(restaurantId: $restaurantId) {
_id
zone {
_id
}
orderId
restaurant {
query GetActiveOrders(
$restaurantId: ID
$page: Int
$rowsPerPage: Int
$actions: [String]
$search: String
) {
getActiveOrders(
restaurantId: $restaurantId
page: $page
rowsPerPage: $rowsPerPage
actions: $actions
search: $search
) {
totalCount
orders {
_id
name
image
address
location {
coordinates
zone {
_id
}
}
deliveryAddress {
location {
coordinates
orderId
restaurant {
_id
name
image
address
location {
coordinates
}
}
deliveryAddress {
location {
coordinates
}
deliveryAddress
}
user {
name
phone
}
paymentMethod
orderStatus
isPickedUp
status
isActive
createdAt
rider {
_id
name
username
available
}
deliveryAddress
}
paymentMethod
orderStatus
isPickedUp
status
isActive
createdAt
rider {
_id
name
username
available
assigned
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import { createContext, useState } from 'react';
// Interface
import {
ICategory,
IOptions,
IProvider,
ISubCategory,
RestaurantLayoutContextData,
RestaurantLayoutContextProps,
} from '@/lib/utils/interfaces';

// Utils
import { SELECTED_RESTAURANT } from '../../utils/constants';
import { onUseLocalStorage } from '../../utils/methods';

Expand All @@ -21,10 +24,22 @@ export const RestaurantLayoutContext =
);

export const RestaurantLayoutProvider = ({ children }: IProvider) => {
// States
const [isAddOptionsVisible, setIsAddOptionsVisible] = useState(false);
const [option, setOption] = useState<IOptions | null>(null);
const [restaurantLayoutContextData, setRestaurantLayoutContextData] =
useState<RestaurantLayoutContextData>({
restaurantId: onUseLocalStorage('get', SELECTED_RESTAURANT),
} as RestaurantLayoutContextData);
const [isAddSubCategoriesVisible, setIsAddSubCategoriesVisible] = useState({
bool: false,
parentCategoryId: '',
});
const [category, setCategory] = useState<ICategory | null>(null);
const [isSubCategoryModalOpen, setIsSubCategoryModalOpen] =
useState<boolean>(false);
const [subCategories, setSubCategories] = useState<ISubCategory[]>([]);
const [subCategoryParentId, setSubCategoryParentId] = useState<string>('');

// Handlers
const onSetRestaurantLayoutContextData = (
Expand All @@ -35,15 +50,6 @@ export const RestaurantLayoutProvider = ({ children }: IProvider) => {
...data,
}));
};
const [isAddSubCategoriesVisible, setIsAddSubCategoriesVisible] = useState({
bool: false,
parentCategoryId: '',
});
const [category, setCategory] = useState<ICategory | null>(null);
const [isSubCategoryModalOpen, setIsSubCategoryModalOpen] =
useState<boolean>(false);
const [subCategories, setSubCategories] = useState<ISubCategory[]>([]);
const [subCategoryParentId, setSubCategoryParentId] = useState<string>('');
const value: RestaurantLayoutContextProps = {
restaurantLayoutContextData,
onSetRestaurantLayoutContextData,
Expand All @@ -57,6 +63,10 @@ export const RestaurantLayoutProvider = ({ children }: IProvider) => {
setIsSubCategoryModalOpen,
subCategoryParentId,
setSubCategoryParentId,
isAddOptionsVisible,
setIsAddOptionsVisible,
option,
setOption
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ import { Sidebar } from 'primereact/sidebar';
import { IAddonForm } from '@/lib/utils/interfaces/forms';

// Components
import CustomButton from '@/lib/ui/useable-components/button';
import CustomMultiSelectComponent from '@/lib/ui/useable-components/custom-multi-select';
import CustomTextAreaField from '@/lib/ui/useable-components/custom-text-area-field';
import CustomTextField from '@/lib/ui/useable-components/input-field';
import CustomNumberField from '@/lib/ui/useable-components/number-input-field';
import TextIconClickable from '@/lib/ui/useable-components/text-icon-clickable';
import OptionsAddForm from '@/lib/ui/screen-components/protected/restaurant/options/add-form';

// Utilities and Constants
import { AddonsErrors, OptionErrors } from '@/lib/utils/constants';

//Toast
import useToast from '@/lib/hooks/useToast';
Expand All @@ -23,13 +31,6 @@ import {
} from '@/lib/api/graphql';
import { RestaurantLayoutContext } from '@/lib/context/restaurant/layout-restaurant.context';
import { useQueryGQL } from '@/lib/hooks/useQueryQL';
import CustomButton from '@/lib/ui/useable-components/button';
import CustomMultiSelectComponent from '@/lib/ui/useable-components/custom-multi-select';
import CustomTextAreaField from '@/lib/ui/useable-components/custom-text-area-field';
import CustomTextField from '@/lib/ui/useable-components/input-field';
import CustomNumberField from '@/lib/ui/useable-components/number-input-field';
import TextIconClickable from '@/lib/ui/useable-components/text-icon-clickable';
import { AddonsErrors, OptionErrors } from '@/lib/utils/constants';
import {
IAddonAddFormComponentProps,
IDropdownSelectItem,
Expand Down Expand Up @@ -72,13 +73,17 @@ export default function AddonAddForm({
addon,
position = 'right',
isAddAddonVisible,

}: IAddonAddFormComponentProps) {
// Hooks
const t = useTranslations();
const { showToast } = useToast();
// Context

const { restaurantLayoutContextData } = useContext(RestaurantLayoutContext);
const { restaurantLayoutContextData , setIsAddOptionsVisible,
option,
setOption,
isAddOptionsVisible,} = useContext(RestaurantLayoutContext);
const restaurantId = restaurantLayoutContextData?.restaurantId || '';

const [initialValues, setInitialValues] = useState({
Expand Down Expand Up @@ -218,14 +223,14 @@ export default function AddonAddForm({
visible={isAddAddonVisible}
position={position}
onHide={onHide}
className="w-full sm:w-[450px]"
className="w-full sm:w-[500px]"
>
<div className="flex h-full w-full items-center justify-start">
<div className="h-full w-full">
<div className="flex flex-col gap-2">
<div className="mb-2 flex flex-col">
<span className="text-lg">
{addon ? t('Edit') : t('Add')} {t('Option')}
{addon ? t('Edit') : t('Add')} {t('Addons')}
</span>
</div>

Expand Down Expand Up @@ -274,7 +279,7 @@ export default function AddonAddForm({
</button>
)}
<Fieldset
legend={`Addon ${index + 1} ${value.title ? `(${value.title})` : ''}`}
legend={`${t('Addons')} ${index + 1} ${value.title ? `(${value.title})` : ''}`}
toggleable
>
<div className="grid grid-cols-12 gap-4">
Expand Down Expand Up @@ -394,6 +399,14 @@ export default function AddonAddForm({
setSelectedItems={
setFieldValue
}
extraFooterButton={{
onChange: () => {
setIsAddOptionsVisible(
true
);
},
title: 'Add Options',
}}
showLabel={true}
style={{
borderColor:
Expand Down Expand Up @@ -449,6 +462,14 @@ export default function AddonAddForm({
</div>
</div>
</div>
<OptionsAddForm
option={option}
onHide={() => {
setIsAddOptionsVisible(false);
setOption(null);
}}
isAddOptionsVisible={isAddOptionsVisible}
/>
</Sidebar>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function CategoryAddForm({
category,
position = 'right',
isAddCategoryVisible,
refetchCategories
}: ICategoryAddFormComponentProps) {
// Hooks
const t = useTranslations();
Expand Down Expand Up @@ -136,6 +137,10 @@ export default function CategoryAddForm({
message: `${t('Category has been')} ${category ? t('edited') : t('added')} ${t('successfully')}.`,
duration: 3000,
});
// Safely call refetchCategories if it exists
if (typeof refetchCategories === 'function') {
refetchCategories();
}
onHide();
},
onError: (error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function FoodDetails({
GET_CATEGORY_BY_RESTAURANT_ID,
{ id: restaurantId ?? '' },
{
fetchPolicy: 'cache-and-network',
fetchPolicy: 'no-cache',
enabled: !!restaurantId,
}
) as IQueryResult<ICategoryByRestaurantResponse | undefined, undefined>;
Expand Down Expand Up @@ -136,7 +136,7 @@ export default function FoodDetails({
data?.restaurant?.categories.map((category: ICategory) => {
return { label: category.title, code: category._id };
}),
[]
[data?.restaurant?.categories]
);

const subCategoriesDropdown = useMemo(
Expand Down Expand Up @@ -425,6 +425,7 @@ export default function FoodDetails({
}}
isAddCategoryVisible={isAddCategoryVisible}
subCategories={subCategories}
refetchCategories = {refetchCategories}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export default function VariationAddForm({
useContext(FoodsContext);
const {
restaurantLayoutContextData: { restaurantId },
option,
setOption
} = useContext(RestaurantLayoutContext);

// Constants
Expand Down Expand Up @@ -471,15 +473,21 @@ export default function VariationAddForm({
</div>
</div>
</div>

<AddonAddForm
addon={addon}
onHide={() => {
setIsAddAddonVisible(false);
setAddon(null);
}}
isAddAddonVisible={isAddAddonVisible}
/>
<div>
<AddonAddForm
className='z-[999]'
isAddOptionsVisible={isAddAddonVisible}
setIsAddOptionsVisible={setIsAddAddonVisible}
option={option}
setOption={setOption}
addon={addon}
onHide={() => {
setIsAddAddonVisible(false);
setAddon(null);
}}
isAddAddonVisible={isAddAddonVisible}
/>
</div>
</div>
);
}
Loading

0 comments on commit b0eedd8

Please sign in to comment.