diff --git a/.gitignore b/.gitignore index 4bd539d..3a6cce9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ yarn-error.log* # Misc .DS_Store out + +.yarn +.idea diff --git a/README.md b/README.md index d6cb0ae..ce01d26 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# carbon-offset-app +# Order custom actions template This project was bootstrapped with [Create Wix App](https://www.npmjs.com/package/@wix/create-app). Read more about it in the [Wix CLI for Apps diff --git a/src/backend/api/orders/api.ts b/src/backend/api/orders/api.ts new file mode 100644 index 0000000..acaf82e --- /dev/null +++ b/src/backend/api/orders/api.ts @@ -0,0 +1,8 @@ +import {orders} from '@wix/ecom'; +import {getOrder} from "../../orders"; + +export async function GET(req: Request) { + const _id = new URL(req.url).searchParams.get('orderId') as string; + const order = await getOrder(_id); + return new Response(JSON.stringify(order ?? {})); +} diff --git a/src/backend/database.ts b/src/backend/database.ts index 687c959..ec670dc 100644 --- a/src/backend/database.ts +++ b/src/backend/database.ts @@ -11,7 +11,7 @@ type DataItem = { export const getDataFromCollection = async ({ dataCollectionId }: { dataCollectionId: string }) => { - const data = await auth.elevate(items.queryDataItems)({ + const data = await items.queryDataItems({ dataCollectionId, }).find(); @@ -23,7 +23,7 @@ export const safelyGetItemFromCollection = async ({ itemId }: { dataCollectionId: string; itemId: string }) => { try { - const { data } = await auth.elevate(items.getDataItem)( + const { data } = await items.getDataItem( itemId, { dataCollectionId }, ); @@ -42,7 +42,7 @@ export const upsertDataToCollection = async ({ const existsInCollection = item._id && collection.items.find(existingItem => existingItem._id === item._id); if (item._id && existsInCollection) { - await auth.elevate(items.updateDataItem)(item._id, { + await items.updateDataItem(item._id, { dataCollectionId, dataItem: { data: { @@ -52,7 +52,7 @@ export const upsertDataToCollection = async ({ }, }); } else { - await auth.elevate(items.insertDataItem)({ + await items.insertDataItem({ dataCollectionId, dataItem: { _id: item._id ?? undefined, diff --git a/src/backend/orders.ts b/src/backend/orders.ts new file mode 100644 index 0000000..a7c9f38 --- /dev/null +++ b/src/backend/orders.ts @@ -0,0 +1,20 @@ +import {orders} from '@wix/ecom'; + +export async function getOrder(_id: string): Promise { + //https://dev.wix.com/docs/sdk/backend-modules/ecom/orders/get-order + const order = await orders.getOrder(_id); + return order; +} + +export function getBuyerPhoneNumber(order: orders.Order): string | null | undefined { + if(order.billingInfo) return order.billingInfo?.contactDetails?.phone; + else if(order.shippingInfo) return order.recipientInfo?.contactDetails?.phone; + else{ + console.log(`No phone number found in order ${JSON.stringify(order)}`); + return null; + } +} + +export function getBuyerLanguage(order: orders.Order): string | null | undefined { + return order.buyerLanguage +} diff --git a/src/dashboard/menu-plugins/my-plugin/plugin.json b/src/dashboard/menu-plugins/my-plugin/plugin.json new file mode 100644 index 0000000..0d87279 --- /dev/null +++ b/src/dashboard/menu-plugins/my-plugin/plugin.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://dev.wix.com/wix-cli/schemas/dashboard-menu-plugin.json", + "id": "440141de-a590-45f6-87a3-0640a8d845ca", + "title": "Whats Upsell", + "iconKey": "Payment", + "extends": "7c82ce37-3890-4613-9364-03a363c92ebe", + "action": { + "openModal": { + "componentId": "3259acd9-9b12-4f5d-9ace-737a5eb73876", + "componentParams": {} + } + } +} diff --git a/src/dashboard/modals/whatup-modals/modal.json b/src/dashboard/modals/whatup-modals/modal.json new file mode 100644 index 0000000..541ca49 --- /dev/null +++ b/src/dashboard/modals/whatup-modals/modal.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://dev.wix.com/wix-cli/schemas/dashboard-modal.json", + "id": "3259acd9-9b12-4f5d-9ace-737a5eb73876", + "title": "message-modal", + "width": 850, + "height": 900 +} diff --git a/src/dashboard/modals/whatup-modals/modal.tsx b/src/dashboard/modals/whatup-modals/modal.tsx new file mode 100644 index 0000000..13a8ebf --- /dev/null +++ b/src/dashboard/modals/whatup-modals/modal.tsx @@ -0,0 +1,62 @@ +import React, { type FC, useState } from 'react'; +import { dashboard } from '@wix/dashboard'; +import { + WixDesignSystemProvider, + Text, + Box, + CustomModalLayout, Dropdown, +} from '@wix/design-system'; +import '@wix/design-system/styles.global.css'; +import { width, height } from './modal.json'; + +// To open your modal, call `openModal` with your modal id. +// e.g. +// import { dashboard } from '@wix/dashboard'; +// function MyComponent() { +// return ; +// } +const Modal: FC = (props: {orderId: string}) => { + const orderId = props.orderId; + console.log('orderId:', orderId); + + const [selectedProduct, setSelectedProduct] = useState(''); + + const productOptions = [ + { id: 'product1', value: 'Product 1' }, + { id: 'product2', value: 'Product 2' }, + { id: 'product3', value: 'Product 3' }, + ]; + + return ( + + dashboard.closeModal()} + primaryButtonOnClick={() => { + console.log('Selected product:', selectedProduct); + dashboard.closeModal(); + }} secondaryButtonOnClick={() => dashboard.closeModal()} + title="Upsell with whatsup" + subtitle="selcet products to resale" + content={ + + setSelectedProduct(option.id)} + /> + + Wix CLI Modal + + + } + /> + + ); +}; + +export default Modal; diff --git a/wix.config.json b/wix.config.json index ec5f50a..7883628 100644 --- a/wix.config.json +++ b/wix.config.json @@ -1,5 +1,5 @@ { "$schema": "https://dev.wix.com/wix-cli/schemas/wix-config.json", - "appId": "a21a2d2f-e642-4195-adcc-ccdd389ba3c0", - "projectId": "standalone-carbon-offset" + "appId": "9f95a5e9-9723-4183-8025-3e15bcad4960", + "projectId": "custom-order-action-template" }