Processing order...
;
-
- if (placeOrderResult) {
- return
-
+
{true ? (
<>
diff --git a/apps/client/tailwind.config.ts b/apps/client/tailwind.config.ts
index f2142668..a3247af0 100644
--- a/apps/client/tailwind.config.ts
+++ b/apps/client/tailwind.config.ts
@@ -21,8 +21,8 @@ const extendedConfig: Config = {
theme: {
...baseConfig.theme,
fontFamily: {
- inter: ['var(--font-inter)'],
- jakarta: ['var(--font-jakarta)'],
+ inter: ["var(--font-inter)"],
+ jakarta: ["var(--font-jakarta)"],
},
extend: {
...baseConfig.theme?.extend,
diff --git a/apps/client/types.d.ts b/apps/client/types.d.ts
new file mode 100644
index 00000000..46cd38d3
--- /dev/null
+++ b/apps/client/types.d.ts
@@ -0,0 +1,11 @@
+// https://github.com/nextauthjs/next-auth/discussions/536#discussioncomment-1932922
+import NextAuth, { DefaultSession } from "next-auth";
+
+declare module "next-auth" {
+ interface Session {
+ user: {
+ id: string;
+ address: string;
+ } & DefaultSession["user"];
+ }
+}
diff --git a/apps/courier/next.config.mjs b/apps/courier/next.config.js
similarity index 74%
rename from apps/courier/next.config.mjs
rename to apps/courier/next.config.js
index 3be6379d..84d0e949 100644
--- a/apps/courier/next.config.mjs
+++ b/apps/courier/next.config.js
@@ -1,7 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
- transpilePackages: ['@sahil/lib', 'ui', '@sahil/configs', "@sahil/features"],
+ transpilePackages: ['@sahil/lib', 'ui', '@sahil/configs', "@sahil/features", "tsconfig", "eslint-config-custom"],
images: {
remotePatterns: [
{
@@ -11,6 +11,7 @@ const nextConfig = {
},
],
},
+ output: "standalone"
};
-export default nextConfig;
+module.exports = nextConfig;
diff --git a/apps/courier/package.json b/apps/courier/package.json
index 9d6c5eab..64594538 100644
--- a/apps/courier/package.json
+++ b/apps/courier/package.json
@@ -8,17 +8,41 @@
"start": "next start"
},
"dependencies": {
+ "@apollo/client": "^3.8.1",
+ "@apollo/react-hooks": "^4.0.0",
+ "@formkit/auto-animate": "^0.7.0",
+ "@hookform/resolvers": "^3.3.0",
+ "@react-google-maps/api": "^2.19.2",
"@sahil/configs": "*",
"@sahil/features": "*",
"@sahil/lib": "*",
+ "@types/jsonwebtoken": "^9.0.5",
+ "apollo-link-ws": "^1.0.20",
+ "autoprefixer": "10.4.15",
"daisyui": "^4.12.2",
+ "date-fns": "^2.30.0",
+ "eslint": "8.47.0",
+ "eslint-config-custom": "*",
"eslint-config-next": "^14.2.3",
+ "graphql": "^16.8.0",
+ "graphql-ws": "^5.14.0",
+ "jsonwebtoken": "^9.0.2",
"next": "^14.2.3",
"next-auth": "^4.24.7",
"next-auth-hasura-adapter": "^2.0.0",
+ "postcss": "8.4.28",
"react": "^18.3.1",
"react-dom": "^18.3.1",
- "ui": "*"
+ "react-hook-form": "^7.45.4",
+ "react-hot-toast": "^2.4.1",
+ "react-icons": "^4.12.0",
+ "subscriptions-transport-ws": "^0.11.0",
+ "swr": "^2.2.1",
+ "tailwindcss": "3.3.3",
+ "tsconfig": "*",
+ "ui": "*",
+ "zod": "3.21.4",
+ "zustand": "^4.4.1"
},
"devDependencies": {
"@types/node": "^20",
diff --git a/apps/courier/src/Layout/layout.tsx b/apps/courier/src/Layout/layout.tsx
index 10c822dc..d1c155fa 100644
--- a/apps/courier/src/Layout/layout.tsx
+++ b/apps/courier/src/Layout/layout.tsx
@@ -6,10 +6,7 @@ import { Navbar } from "ui";
type LayoutProps = {
children: ReactNode;
};
-import {
- HiOutlineQueueList,
- HiOutlineTruck,
-} from "react-icons/hi2";
+import { HiOutlineQueueList, HiOutlineTruck } from "react-icons/hi2";
const links = [
{
@@ -43,9 +40,7 @@ export default function Layout({ children, ...props }: LayoutProps) {
user={session?.user}
/>
)}
-
- {children}
-
+
{children}
>
);
}
diff --git a/apps/courier/src/config.ts b/apps/courier/src/config.ts
new file mode 100644
index 00000000..7931068f
--- /dev/null
+++ b/apps/courier/src/config.ts
@@ -0,0 +1,48 @@
+import { z } from 'zod';
+
+const envSchema = z.object({
+ // Server
+ SERVER_URL: z.string().url(),
+
+ // Hasura
+ HASURA_GRAPHQL_CORS_DOMAIN: z.string(),
+ NEXT_PUBLIC_HASURA_GRAPHQL_ENDPOINT: z.string().url(),
+ NEXT_PUBLIC_HASURA_GRAPHQL_ADMIN_SECRET: z.string(),
+ NEXT_PUBLIC_HASURA_GRAPHQL_WS: z.string().url(),
+
+ // Auth
+ SECRET: z.string(),
+ NEXTAUTH_SECRET: z.string(),
+ NEXT_PUBLIC_NEXTAUTH_URL: z.string().url(),
+
+ // APIs
+ NEXT_PUBLIC_GITHUB_SECRET: z.string(),
+ NEXT_PUBLIC_GITHUB_ID: z.string(),
+ NEXT_PUBLIC_GOOGLE_SECRET: z.string(),
+ NEXT_PUBLIC_GOOGLE_API_KEY: z.string().optional(),
+ NEXT_PUBLIC_GOOGLE_ID: z.string(),
+
+ // Database
+ POSTGRES_USER: z.string(),
+ POSTGRES_PASSWORD: z.string(),
+ POSTGRES_DATABASE: z.string(),
+
+ // App URLs
+ ADMIN_URL: z.string().url(),
+ AGENT_URL: z.string().url(),
+ CLIENT_URL: z.string().url(),
+ COURIER_URL: z.string().url(),
+ API_URL: z.string().url(),
+
+ // Email
+ EMAIL_SERVER_USER: z.string(),
+ EMAIL_SERVER_PASSWORD: z.string(),
+ EMAIL_SERVER_HOST: z.string(),
+ EMAIL_SERVER_PORT: z.string(),
+ EMAIL_FROM: z.string().email(),
+ EMAIL_SERVER: z.string(),
+});
+
+const env = envSchema.parse(process.env);
+
+export default env;
diff --git a/apps/courier/src/pages/deliveries/[deliveryId].tsx b/apps/courier/src/pages/deliveries/[deliveryId].tsx
index 0ac04afe..f8ddc8c9 100644
--- a/apps/courier/src/pages/deliveries/[deliveryId].tsx
+++ b/apps/courier/src/pages/deliveries/[deliveryId].tsx
@@ -1,5 +1,88 @@
- import { useRouter } from "next/router";
+import { useRouter } from "next/router";
import { useFetchDeliveryByPK } from "@sahil/lib/hooks/deliveries";
+import { Card } from "ui";
+import { OrderItem } from "@sahil/features/Orders/OrderItems";
+import { OrderInfoItem } from "@sahil/features/Orders/OrderDetails";
+import { formatDateTime } from "@sahil/lib/dates";
+import {
+ HiCalendarDays,
+ HiOutlineBanknotes,
+ HiOutlineBriefcase,
+ HiOutlineMap,
+ HiOutlineMapPin,
+ HiOutlineCheck,
+ HiOutlineTruck,
+} from "react-icons/hi2";
+
+const DeliveryOrders = ({ order, deliveryStatus, onUpdateStatus }) => {
+ console.log(order);
+ return (
+
+ {order?.order_items.map((order) => (
+
+ Order Details
+ Delivery Order ID: {order.id}
+ {order?.order_items && order?.order_items?.length > 0 ? (
+
+ {order.order_items.map((item, index) => (
+
+ ))}
+
+ ) : (
+ No items found for this order.
+ )}
+
+
+ ))}
+
+ );
+};
+
+const DeliveryActions = ({ orderId, deliveryStatus, onUpdateStatus }) => {
+ return (
+
+
+
+
+
+ );
+};
+
+// Stub for useUpdateDeliveryStatus hook
+const useUpdateDeliveryStatus = () => {
+ const updateDeliveryStatus = async (orderId: string, newStatus: string) => {
+ console.log(`Updating order ${orderId} to status ${newStatus}`);
+ // Implement actual update logic here when the hook is ready
+ };
+
+ return { updateDeliveryStatus };
+};
export default function DeliveryPage() {
const router = useRouter();
@@ -9,8 +92,82 @@ export default function DeliveryPage() {
error,
loading,
} = useFetchDeliveryByPK(deliveryId as string);
- if (error) return
error
;
- if (loading) return
loading
;
- if (delivery?.length === 0) return
No delivery found
;
- return
Delivery Page
;
+ const { updateDeliveryStatus } = useUpdateDeliveryStatus();
+
+ if (error) return
Error loading delivery information
;
+ if (loading) return
Loading delivery information...
;
+ if (!delivery) return
No delivery found
;
+
+ const deliveryInfoItems = [
+ {
+ icon:
,
+ label: "Payment Method",
+ value: "N/A",
+ },
+ {
+ icon:
,
+ label: "Client",
+ value: "N/A",
+ },
+ {
+ icon:
,
+ label: "Status",
+ value: "N/A",
+ },
+ ];
+
+ const handleUpdateStatus = async (orderId, newStatus) => {
+ try {
+ await updateDeliveryStatus(orderId, newStatus);
+ // Optionally, you can refetch the delivery data here to update the UI
+ } catch (error) {
+ console.error("Failed to update delivery status:", error);
+ }
+ };
+
+ console.log(delivery[0]?.order);
+
+ return (
+
+
+
+
+ {deliveryInfoItems.map((item, index) => (
+
+ ))}
+
+
+
+
+
+ {/* {
+
+ delivery.status === 'pending' && (
+
+ )} */}
+
+
+
+
+ );
}
diff --git a/apps/courier/src/pages/requests/[requestId].tsx b/apps/courier/src/pages/requests/[requestId].tsx
index d7e33812..a38cb4d0 100644
--- a/apps/courier/src/pages/requests/[requestId].tsx
+++ b/apps/courier/src/pages/requests/[requestId].tsx
@@ -1,45 +1,58 @@
import { useRouter } from "next/router";
import { useFetchDeliveryRequestByPK } from "@sahil/lib/hooks/deliveries";
-import { BusinessOverviewCard } from "@sahil/features/businesses/BusinessOverviewCard";
+import { Card } from "ui";
+import { OrderItem } from "@sahil/features/Orders/OrderItems";
+import { OrderInfoItem } from "@sahil/features/Orders/OrderDetails";
+import { formatDateTime } from "@sahil/lib/dates";
+import {
+ HiCalendarDays,
+ HiOutlineBanknotes,
+ HiOutlineBriefcase,
+} from "react-icons/hi2";
-const orders = [
- {
- id: "1",
- name: "Order 1",
- status: "pending",
- items: [
- {
- id: "1",
- name: "Item 1",
- quantity: 1,
- },
- ],
- client: {
- id: "1",
- name: "Client 1",
- },
- },
-];
-
-const RequestOrders = () => {
+const RequestOrders = ({ orders, isSingleOrder }) => {
return (
-
Business Name
-
- {orders.map((order) => (
-
-
-
{order.name}
-
{order.status}
-
-
- ))}
+
+ {orders.map((order) => {
+ return (
+
+ Order Details
+ Delivery Request Order ID: {order.id}
+ {order?.order?.order_items &&
+ order?.order?.order_items?.length > 0 ? (
+
+ {order?.order?.order_items.map((item, index) => (
+
+ ))}
+
+ ) : (
+ No items found for this order.
+ )}
+ {!isSingleOrder && (
+
+ )}
+
+ );
+ })}
- )
-}
-
+ );
+};
+export const RequestActions = () => {
+ return (
+
+
+
+
+ );
+};
export default function RequestPage() {
const router = useRouter();
@@ -51,13 +64,46 @@ export default function RequestPage() {
} = useFetchDeliveryRequestByPK(requestId as string);
if (error) return
error
;
if (loading) return
loading
;
- if (deliveryRequest?.length === 0) return
No delivery request found
;
+ if (!deliveryRequest) return
No delivery request found
;
+
+ const orderInfoItems = [
+ {
+ icon:
,
+ label: "Order Date",
+ value: formatDateTime(deliveryRequest[0].created_at),
+ },
+ {
+ icon:
,
+ label: "Payment Method",
+ value: "Cash on Delivery",
+ },
+ ];
+
+ const isSingleOrder = deliveryRequest[0].delivery_request_orders.length === 1;
return (
-
- Request Page
- {deliveryRequest?.id}
-
+
+
+
+
+ {orderInfoItems.map((item, index) => (
+
+ ))}
+
+ {isSingleOrder && (
+
+ )}
+
+
+
);
}
diff --git a/apps/courier/types.d.ts b/apps/courier/types.d.ts
new file mode 100644
index 00000000..46cd38d3
--- /dev/null
+++ b/apps/courier/types.d.ts
@@ -0,0 +1,11 @@
+// https://github.com/nextauthjs/next-auth/discussions/536#discussioncomment-1932922
+import NextAuth, { DefaultSession } from "next-auth";
+
+declare module "next-auth" {
+ interface Session {
+ user: {
+ id: string;
+ address: string;
+ } & DefaultSession["user"];
+ }
+}
diff --git a/codegen.ts b/codegen.ts
index 063a9359..a8217bad 100644
--- a/codegen.ts
+++ b/codegen.ts
@@ -22,7 +22,7 @@ const config: CodegenConfig = {
preset: "client",
presetConfig: {
gqlTagName: "gql",
- fragmentMasking: false
+ fragmentMasking: false,
},
},
},
diff --git a/docker-compose.yml b/docker-compose.yml
index 72da5f0a..940bc066 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -65,6 +65,36 @@ services:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DATABASE=${POSTGRES_DATABASE}
+ # ADMIN
+ sahil-admin:
+ container_name: sahil-admin
+ build:
+ context: .
+ dockerfile: ./infra/docker/Dockerfile.admin
+ image: sahil-admin
+ restart: always
+ ports:
+ - '3003:3000'
+ environment:
+ - POSTGRES_USER=${POSTGRES_USER}
+ - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
+ - POSTGRES_DATABASE=${POSTGRES_DATABASE}
+
+ # COURIER
+ sahil-courier:
+ container_name: sahil-courier
+ build:
+ context: .
+ dockerfile: ./infra/docker/Dockerfile.courier
+ image: sahil-courier
+ restart: always
+ ports:
+ - '3004:3000'
+ environment:
+ - POSTGRES_USER=${POSTGRES_USER}
+ - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
+ - POSTGRES_DATABASE=${POSTGRES_DATABASE}
+
#### LOCAL DEV ENVIRONMENTS ####
# HASURA ENGINE
@@ -115,9 +145,9 @@ services:
retries: 5
start_period: 5s
- # API
- sahil-api-local-dev:
- container_name: sahil-redis-postgres
+ # Redis
+ sahil-redis:
+ container_name: sahil-redis
image: redis:6.0-alpine
restart: always
environment:
diff --git a/infra/docker/Dockerfile.admin b/infra/docker/Dockerfile.admin
new file mode 100644
index 00000000..127c2480
--- /dev/null
+++ b/infra/docker/Dockerfile.admin
@@ -0,0 +1,56 @@
+ARG NODE_VERSION=18.17.0
+
+FROM node:${NODE_VERSION}-alpine As base
+
+FROM base AS builder
+RUN apk add --no-cache libc6-compat
+RUN apk update
+# Set working directory
+WORKDIR /app
+RUN yarn global add turbo
+COPY . .
+RUN turbo prune admin --docker
+
+# Add lockfile and package.json's of isolated subworkspace
+FROM base AS installer
+RUN apk add --no-cache libc6-compat
+RUN apk update
+WORKDIR /app
+
+# Install the dependencies
+COPY .gitignore .gitignore
+COPY --from=builder /app/out/json/ .
+COPY --from=builder /app/out/yarn.lock ./yarn.lock
+RUN yarn install --network-timeout 100000
+
+# Build the project
+COPY --from=builder /app/out/full/ .
+COPY turbo.json turbo.json
+
+# Remote caching
+# ARG TURBO_TEAM
+# ENV TURBO_TEAM=$TURBO_TEAM
+
+# ARG TURBO_TOKEN
+# ENV TURBO_TOKEN=$TURBO_TOKEN
+
+# || true
+RUN yarn turbo build --filter=admin...
+
+FROM base AS runner
+WORKDIR /app
+
+# Don't run production as root
+RUN addgroup --system --gid 1001 nodejs
+RUN adduser --system --uid 1001 nextjs
+USER nextjs
+
+COPY --from=installer /app/apps/admin/next.config.js .
+COPY --from=installer /app/apps/admin/package.json .
+
+# Reduce image size
+COPY --from=installer --chown=nextjs:nodejs /app/apps/admin/.next/standalone ./
+COPY --from=installer --chown=nextjs:nodejs /app/apps/admin/.next/static ./apps/admin/.next/static
+COPY --from=installer --chown=nextjs:nodejs /app/apps/admin/public ./apps/admin/public
+
+CMD node apps/admin/server.js
\ No newline at end of file
diff --git a/infra/docker/Dockerfile.courier b/infra/docker/Dockerfile.courier
new file mode 100644
index 00000000..554c282a
--- /dev/null
+++ b/infra/docker/Dockerfile.courier
@@ -0,0 +1,56 @@
+ARG NODE_VERSION=18.17.0
+
+FROM node:${NODE_VERSION}-alpine As base
+
+FROM base AS builder
+RUN apk add --no-cache libc6-compat
+RUN apk update
+# Set working directory
+WORKDIR /app
+RUN yarn global add turbo
+COPY . .
+RUN turbo prune courier --docker
+
+# Add lockfile and package.json's of isolated subworkspace
+FROM base AS installer
+RUN apk add --no-cache libc6-compat
+RUN apk update
+WORKDIR /app
+
+# Install the dependencies
+COPY .gitignore .gitignore
+COPY --from=builder /app/out/json/ .
+COPY --from=builder /app/out/yarn.lock ./yarn.lock
+RUN yarn install --network-timeout 100000
+
+# Build the project
+COPY --from=builder /app/out/full/ .
+COPY turbo.json turbo.json
+
+# Remote caching
+# ARG TURBO_TEAM
+# ENV TURBO_TEAM=$TURBO_TEAM
+
+# ARG TURBO_TOKEN
+# ENV TURBO_TOKEN=$TURBO_TOKEN
+
+# || true
+RUN yarn turbo build --filter=courier...
+
+FROM base AS runner
+WORKDIR /app
+
+# Don't run production as root
+RUN addgroup --system --gid 1001 nodejs
+RUN adduser --system --uid 1001 nextjs
+USER nextjs
+
+COPY --from=installer /app/apps/courier/next.config.js .
+COPY --from=installer /app/apps/courier/package.json .
+
+# Reduce image size
+COPY --from=installer --chown=nextjs:nodejs /app/apps/courier/.next/standalone ./
+COPY --from=installer --chown=nextjs:nodejs /app/apps/courier/.next/static ./apps/courier/.next/static
+COPY --from=installer --chown=nextjs:nodejs /app/apps/courier/public ./apps/courier/public
+
+CMD node apps/courier/server.js
\ No newline at end of file
diff --git a/packages/features/Couriers/DeliveryRequestOverview.tsx b/packages/features/Couriers/DeliveryRequestOverview.tsx
deleted file mode 100644
index e27e4847..00000000
--- a/packages/features/Couriers/DeliveryRequestOverview.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import { Avatar, Card, Icon } from "ui";
-
-export const DeliveryRequestOverview = ({ request }) => {
- return (
-
- {request.name}
- Accepted
-
- );
-};
diff --git a/packages/features/Couriers/ListDeliveryRequests.tsx b/packages/features/Couriers/ListDeliveryRequests.tsx
deleted file mode 100644
index a30e5fe4..00000000
--- a/packages/features/Couriers/ListDeliveryRequests.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import { Card } from "ui";
-import { DeliveryRequestOverview } from "./DeliveryRequestOverview";
-
-const requests = [
- {
- id: 1,
- name: "BBQ Pizza",
- },
- {
- id: 2,
- name: "Injera and Tibs",
- },
- {
- id: 3,
- name: "Buffalo Wings",
- },
-];
-
-export const ListDeliveryRequests = () => {
- return (
-
- {requests.map((request) => (
-
- ))}
-
- );
-};
diff --git a/packages/features/Couriers/components/CourierProfileOverview.tsx b/packages/features/Couriers/components/CourierProfileOverview.tsx
index 54d56495..27166ae2 100644
--- a/packages/features/Couriers/components/CourierProfileOverview.tsx
+++ b/packages/features/Couriers/components/CourierProfileOverview.tsx
@@ -7,6 +7,7 @@ type Props = {
};
export const CourierProfileOverview: FC = ({ courier }) => {
+ console.log(courier)
return (
{courier?.avatar &&
}
diff --git a/packages/features/Deliveries/DeliveryOverviewCard.tsx b/packages/features/Deliveries/DeliveryOverviewCard.tsx
index 685d6080..1a392c51 100644
--- a/packages/features/Deliveries/DeliveryOverviewCard.tsx
+++ b/packages/features/Deliveries/DeliveryOverviewCard.tsx
@@ -1,13 +1,11 @@
import { Card } from "ui";
-import {
- HiCalendarDays,
- HiOutlineArrowRight
- } from "react-icons/hi2";
- import Link from "next/link";
+import { HiCalendarDays, HiOutlineArrowRight } from "react-icons/hi2";
+import Link from "next/link";
export const DeliveryOverviewCard = ({ delivery }: { delivery: any }) => {
+ console.log(delivery);
return (
-
+
{delivery.status}
@@ -22,7 +20,12 @@ export const DeliveryOverviewCard = ({ delivery }: { delivery: any }) => {
{delivery.deliveryType}
{delivery.totalAmount}
-
View Details
+
+ View Details
+
);
};
diff --git a/packages/features/Deliveries/DeliveryRequestOverviewCard.tsx b/packages/features/Deliveries/DeliveryRequestOverviewCard.tsx
index 5ced98a7..79b7dc78 100644
--- a/packages/features/Deliveries/DeliveryRequestOverviewCard.tsx
+++ b/packages/features/Deliveries/DeliveryRequestOverviewCard.tsx
@@ -1,39 +1,43 @@
import { FC } from "react";
import { Card } from "ui";
-import {
- HiCalendarDays,
- HiOutlineArrowRight
-} from "react-icons/hi2";
+import { HiCalendarDays, HiOutlineArrowRight } from "react-icons/hi2";
import Link from "next/link";
-export const DeliveryRequestOverviewCard = ({ request }) => {
- const hasActions = false;
+export const DeliveryRequestOverviewCard: FC<{ request: any }> = ({ request }) => {
+ console.log(request);
+ const hasActions = false;
+ const createdDate = new Date(request.created_at);
+ const updatedDate = new Date(request.updated_at);
+
return (
-
+
{request.status}
-
{request.date}
+
{createdDate.toLocaleDateString()}
-
{request.time}
-
{request.location}
+
{createdDate.toLocaleTimeString()}
+
Courier ID: {request?.courierId?.slice(0, 8)}
-
{request.deliveryType}
-
{request.totalAmount}
+
Delivery Method: {request.delivery_method || 'Not specified'}
+
Orders: {request.delivery_request_orders.length}
+ Last Updated: {updatedDate.toLocaleString()}
{hasActions && (
)}
- View Details
+
+ View Details
+
);
};
diff --git a/packages/features/Deliveries/ListDeliveries.tsx b/packages/features/Deliveries/ListDeliveries.tsx
index 66b1c338..13ea81de 100644
--- a/packages/features/Deliveries/ListDeliveries.tsx
+++ b/packages/features/Deliveries/ListDeliveries.tsx
@@ -2,50 +2,14 @@ import { DeliveryOverviewCard } from "./DeliveryOverviewCard";
import { List, ListHeader, ListErrorState, ListPagination } from "ui";
import { useFetchDeliveries } from "@sahil/lib/hooks/deliveries";
-const deliveries = [
- {
- id: 1,
- name: "Delivery 1",
- status: "Delivered",
- date: "Oct 1st, 2022",
- time: "12:00 PM",
- location: "New York, NY",
- deliveryType: "Home Delivery",
- totalAmount: "$100.00",
- orderId: 1,
- },
- {
- id: 2,
- name: "Delivery 2",
- status: "Delivered",
- date: "Oct 1st, 2022",
- time: "12:00 PM",
- location: "New York, NY",
- deliveryType: "Home Delivery",
- totalAmount: "$100.00",
- orderId: 2,
- },
- {
- id: 3,
- name: "Delivery 3",
- status: "Delivered",
- date: "Oct 1st, 2022",
- time: "12:00 PM",
- location: "New York, NY",
- deliveryType: "Home Delivery",
- totalAmount: "$100.00",
- orderId: 3,
- },
-]
-
export const ListDeliveries = () => {
- const { data, loading, error } = useFetchDeliveries();
+ const { data: deliveries, loading, error } = useFetchDeliveries();
if (loading) return Loading...
;
if (error) return Error: {error.message}
;
- console.log(data);
+ console.log(deliveries);
return (
);
-};
\ No newline at end of file
+};
diff --git a/packages/features/Deliveries/ListDeliveryRequests.tsx b/packages/features/Deliveries/ListDeliveryRequests.tsx
index 505bf5e9..f39d06c9 100644
--- a/packages/features/Deliveries/ListDeliveryRequests.tsx
+++ b/packages/features/Deliveries/ListDeliveryRequests.tsx
@@ -2,53 +2,16 @@ import { DeliveryRequestOverviewCard } from "./DeliveryRequestOverviewCard";
import { List, ListHeader, ListErrorState, ListPagination } from "ui";
import { useFetchDeliveryRequests } from "@sahil/lib/hooks/deliveries";
-const deliveryRequests = [
- {
- id: 1,
- name: "Delivery Request 1",
- status: "Pending",
- date: "Oct 1st, 2022",
- time: "12:00 PM",
- location: "New York, NY",
- deliveryType: "Home Delivery",
- totalAmount: "$100.00",
- },
- {
- id: 2,
- name: "Delivery Request 2",
- status: "Pending",
- date: "Oct 1st, 2022",
- time: "12:00 PM",
- location: "New York, NY",
- deliveryType: "Home Delivery",
- totalAmount: "$100.00",
- },
- {
- id: 3,
- name: "Delivery Request 3",
- status: "Pending",
- date: "Oct 1st, 2022",
- time: "12:00 PM",
- location: "New York, NY",
- deliveryType: "Home Delivery",
- totalAmount: "$100.00",
- },
-];
-
export const ListDeliveryRequests = () => {
- const { loading, error, data } = useFetchDeliveryRequests();
- if (loading) return Loading...
;
- if (error) return Error :(
;
-
- console.log(error);
- console.log(data);
-
+ const { loading, error, data: deliveryRequests } = useFetchDeliveryRequests();
+ if (error) return ;
return (
(
)}
diff --git a/packages/features/Orders/CancelOrderDialog.tsx b/packages/features/Orders/CancelOrderDialog.tsx
new file mode 100644
index 00000000..531dcf16
--- /dev/null
+++ b/packages/features/Orders/CancelOrderDialog.tsx
@@ -0,0 +1,64 @@
+import React, { useRef } from "react";
+import Modal from "ui/components/Modal";
+import { Order_Status_Enum } from "@sahil/lib/graphql/__generated__/graphql";
+import { useAppendOrderStatus } from "@sahil/lib/hooks/orders";
+import toast from "react-hot-toast";
+
+type CancelOrderDialogProps = {
+ orderId: string;
+ onCancel: () => void;
+};
+
+export const CancelOrderDialog: React.FC = ({ orderId }) => {
+ const closeBtn = useRef(null);
+ const { appendOrderStatus, loading } = useAppendOrderStatus();
+
+ const onCancel = async () => {
+ if (loading) return;
+
+ try {
+ await appendOrderStatus({
+ variables: {
+ object: {
+ order_id: orderId,
+ status: Order_Status_Enum.Canceled,
+ },
+ },
+ });
+ toast.success("Order has been cancelled");
+ } catch (error) {
+ console.error("Error canceling order status:", error);
+ toast.error("Order couldn't be cancelled, try again later.");
+ }
+ };
+
+ return (
+
+ Are you sure you want to cancel this order?
+
+
+
+
+
+ );
+};
+
+
diff --git a/packages/features/Orders/CustomProductsCatalogue.tsx b/packages/features/Orders/CustomProductsCatalogue.tsx
index 9eb6be11..3157acbd 100644
--- a/packages/features/Orders/CustomProductsCatalogue.tsx
+++ b/packages/features/Orders/CustomProductsCatalogue.tsx
@@ -20,16 +20,22 @@ import {
export const CustomProductsCatalogue = () => {
const [offset, setOffset] = useState(0);
- const { data, error, loading, productsCount } = useFetchProducts({ offset });
+ const {
+ data: products,
+ error,
+ loading,
+ productsCount,
+ } = useFetchProducts({ offset });
- const { addOrderItem, orderItems, setProducts, products } =
- useOrderItemsStore((state) => state);
+ const { addOrderItem, orderItems, setProducts } = useOrderItemsStore(
+ (state) => state
+ );
const orderItemsMap = new Map(orderItems.map((item) => [item.id, item]));
useEffect(() => {
- setProducts(data);
- }, [data, setProducts]);
+ if (products) setProducts(products);
+ }, [products, setProducts]);
if (error) {
return (
@@ -91,20 +97,23 @@ export const CustomProductsCatalogue = () => {
>
-
+ {productsCount && (
+
+ )}
-
{productsCount.count} Items
+
{productsCount?.count} Items
);
};
-type OrderInfoItemProps = {
+export type OrderInfoItemProps = {
icon: React.ReactNode;
label: string;
value: string;
};
-
-const OrderInfoItem = ({ icon, label, value }: OrderInfoItemProps) => (
+export const OrderInfoItem = ({ icon, label, value }: OrderInfoItemProps) => (
-
- {icon}
-
+
{icon}
{label}
{value}
-);
\ No newline at end of file
+);
diff --git a/packages/features/Orders/OrderItems.tsx b/packages/features/Orders/OrderItems.tsx
index 4a33456e..321d5713 100644
--- a/packages/features/Orders/OrderItems.tsx
+++ b/packages/features/Orders/OrderItems.tsx
@@ -12,18 +12,18 @@ type OrderItemProps = {
export const OrderItem: FC
= ({ price, quantity, title }) => {
return (
-
+
-
+
{title}
-
- {formatCurrency(parseInt(price))}
-
-
-
-
- {quantity}x
-
+
+
+ {quantity} Quantity
+
+
+ {formatCurrency(parseInt(price))}
+
+
@@ -46,19 +46,21 @@ export const OrderItems: FC
= ({ items }) => {
}
);
return (
- <>
-
-
- {items?.map((item, index) => (
-
- ))}
-
-
- >
+
+
+
+ {items?.map((item, index) => (
+
+ ))}
+
+
);
};
diff --git a/packages/features/Orders/OrderOverview.tsx b/packages/features/Orders/OrderOverview.tsx
index 3d5a33a9..1a2c314b 100644
--- a/packages/features/Orders/OrderOverview.tsx
+++ b/packages/features/Orders/OrderOverview.tsx
@@ -1,22 +1,54 @@
-import { FC } from "react";
-import { Orders } from "@sahil/lib/graphql/__generated__/graphql";
+import { FC, useState, useRef } from "react";
+import {
+ Order_Status_Enum,
+ Orders,
+} from "@sahil/lib/graphql/__generated__/graphql";
+import { useAppendOrderStatus } from "@sahil/lib/hooks/orders";
+import toast, { Toaster } from "react-hot-toast";
import {
HiOutlinePrinter,
HiOutlineArrowPathRoundedSquare,
+ HiOutlineExclamationCircle,
} from "react-icons/hi2";
+import { Card } from "ui";
+import { CancelOrderDialog } from "./CancelOrderDialog";
type Props = {
order: Orders;
};
export const OrderOverview: FC = ({ order }) => {
+ const { appendOrderStatus, loading } = useAppendOrderStatus();
+ const isCanceled =
+ order.status_histories?.[0]?.status === Order_Status_Enum.Canceled;
+
+ const onCancel = async () => {
+ if (loading) return;
+ try {
+ await appendOrderStatus({
+ variables: {
+ object: {
+ order_id: order.id,
+ status: Order_Status_Enum.Canceled,
+ },
+ },
+ });
+ toast.success("Order has been cancelled");
+ } catch (error) {
+ console.error("Error canceling order status:", error);
+ toast.error("Order couldn't be cancelled, try again later.");
+ }
+ };
+
return (
<>
-
+
+
-
- Order ID: #{order.id.slice(0, 8).toLocaleUpperCase()}
-
+
+
+
+
>
);
};
diff --git a/packages/features/Orders/OrderOverviewCard.tsx b/packages/features/Orders/OrderOverviewCard.tsx
index 57be8eed..70ee16e5 100644
--- a/packages/features/Orders/OrderOverviewCard.tsx
+++ b/packages/features/Orders/OrderOverviewCard.tsx
@@ -7,7 +7,7 @@ import {
HiOutlineMapPin,
HiOutlinePhone,
HiEllipsisVertical,
- HiOutlineBriefcase,
+ HiOutlineClock,
HiCalendarDays,
} from "react-icons/hi2";
@@ -34,13 +34,15 @@ export const OrderOverviewCard: FC
= ({ order }) => {
/>
- {order?.status_histories![0]?.status ?? "Pending"}
+ {order?.status_histories![0]?.status ?? "Pending"}
-
Customer
+
+ Customer
+
{order?.business?.name}
diff --git a/packages/features/Orders/OrderPreferences.tsx b/packages/features/Orders/OrderPreferences.tsx
index 3178901f..f568f7c4 100644
--- a/packages/features/Orders/OrderPreferences.tsx
+++ b/packages/features/Orders/OrderPreferences.tsx
@@ -1,46 +1,158 @@
-import { formatDateTime } from "@sahil/lib/dates";
-import { Card } from "ui";
+import { Card, RadioGroup } from "ui";
import { FC } from "react";
import { Orders } from "@sahil/lib/graphql/__generated__/graphql";
+import { paymentMethods, deliveryMethods, notificationOptions, contactMethodOptions } from "./constants";
+import {
+ FieldValues,
+ useForm,
+} from "react-hook-form";
+import { BaseInputProps } from "ui/types";
-import { HiOutlinePrinter } from "react-icons/hi2";
+type BaseProps = BaseInputProps
& {
+ disabled?: boolean;
+};
+
+type RadioGroupProps = Partial & {
+ options: { value: string; label: string }[];
+ disabled?: boolean;
+};
type Props = {
order: Orders;
};
+export const NotificationPreference = ({ register, errors, defaultValue, disabled }: any) => {
+ return (
+
+ );
+};
+
+export const ContactMethodPreference = ({ register, errors, defaultValue, disabled }: any) => {
+ return (
+
+ );
+};
+
+export const PaymentMethodOptions = ({
+ register,
+ errors,
+ defaultValue,
+ disabled
+}: any) => {
+ return (
+
+ );
+};
+
+export const OrderDeliveryOptions = ({
+ register,
+ errors,
+ defaultValue,
+ disabled
+}: any) => {
+ return (
+
+ );
+};
+
export const OrderPreferences: FC = ({ order }) => {
+ const { register, handleSubmit, formState: { errors } } = useForm({
+ defaultValues: {
+ paymentMethod: "",
+ deliveryMethod: "",
+ notifyWhen: "",
+ contactMethod: "",
+ undeliverableAction: "",
+ }
+ });
+
+ const onSubmit = (data: FieldValues) => {
+ console.log(data);
+ // Handle form submission
+ };
+
return (
-
- Review and Confirm Order
-
-
-
-
-
-
-
Review and Confirm Order
+
+
+
);
};
diff --git a/packages/features/Orders/OrderProcessingForm/PaymentDetails.tsx b/packages/features/Orders/OrderProcessingForm/PaymentDetails.tsx
index e4c5873f..a5762b09 100644
--- a/packages/features/Orders/OrderProcessingForm/PaymentDetails.tsx
+++ b/packages/features/Orders/OrderProcessingForm/PaymentDetails.tsx
@@ -4,13 +4,12 @@ import { useRouter } from "next/router";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import { useOrderFormStore } from "@sahil/lib/hooks/formStores/useOrderFormStore";
-import { Card } from "ui";
+import { Card, Icon, RadioGroup } from "ui";
import {
HiXMark,
- HiOutlineCreditCard,
- HiOutlineBanknotes,
HiArrowSmallRight,
} from "react-icons/hi2";
+import { PaymentMethodOptions } from "../OrderPreferences";
const paymentDetailsSchema = z.object({
paymentMethod: z.string(),
@@ -47,36 +46,7 @@ export const PaymentDetails: FC
= ({