From 7aa098e1849d9e55369d7bcfe7854f26506f6d40 Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Mon, 1 Apr 2024 03:12:56 +0200 Subject: [PATCH 1/7] update api --- app/lib/api/bookingShopifyApi.ts | 99 ++++- app/lib/api/model/customerPayout.ts | 19 + .../model/customerPayoutAccountCreateBody.ts | 4 +- ...=> customerPayoutAccountCreateResponse.ts} | 5 +- ...oad.ts => customerPayoutAccountDestroy.ts} | 4 +- .../model/customerPayoutAccountDestroy200.ts | 12 - .../customerPayoutAccountDestroyResponse.ts | 12 + .../api/model/customerPayoutAccountGet200.ts | 12 - ...ts => customerPayoutAccountGetResponse.ts} | 4 +- .../api/model/customerPayoutBalancePayload.ts | 12 + .../model/customerPayoutBalanceResponse.ts | 12 + .../api/model/customerPayoutGetResponse.ts | 12 + .../model/customerPayoutLogPaginateParams.ts | 21 + app/lib/api/model/customerPayoutLogPayload.ts | 15 + .../customerPayoutLogPayloadResultsItem.ts | 12 + .../api/model/customerPayoutLogResponse.ts | 12 + .../api/model/customerPayoutPaginateParams.ts | 21 + .../model/customerPayoutPaginatePayload.ts | 15 + .../model/customerPayoutPaginateResponse.ts | 12 + .../api/model/customerPayoutPayoutDetails.ts | 12 + app/lib/api/model/customerPayoutStatus.ts | 16 + app/lib/api/model/index.ts | 22 +- app/lib/api/model/usersListResponsePayload.ts | 2 +- app/lib/zod/bookingShopifyApi.ts | 263 ++++++++++- openapi.yaml | 411 +++++++++++++++--- 25 files changed, 928 insertions(+), 113 deletions(-) create mode 100644 app/lib/api/model/customerPayout.ts rename app/lib/api/model/{customerPayoutAccountGet200Payload.ts => customerPayoutAccountCreateResponse.ts} (63%) rename app/lib/api/model/{customerPayoutAccountDestroy200Payload.ts => customerPayoutAccountDestroy.ts} (74%) delete mode 100644 app/lib/api/model/customerPayoutAccountDestroy200.ts create mode 100644 app/lib/api/model/customerPayoutAccountDestroyResponse.ts delete mode 100644 app/lib/api/model/customerPayoutAccountGet200.ts rename app/lib/api/model/{customerPayoutAccountCreate200.ts => customerPayoutAccountGetResponse.ts} (81%) create mode 100644 app/lib/api/model/customerPayoutBalancePayload.ts create mode 100644 app/lib/api/model/customerPayoutBalanceResponse.ts create mode 100644 app/lib/api/model/customerPayoutGetResponse.ts create mode 100644 app/lib/api/model/customerPayoutLogPaginateParams.ts create mode 100644 app/lib/api/model/customerPayoutLogPayload.ts create mode 100644 app/lib/api/model/customerPayoutLogPayloadResultsItem.ts create mode 100644 app/lib/api/model/customerPayoutLogResponse.ts create mode 100644 app/lib/api/model/customerPayoutPaginateParams.ts create mode 100644 app/lib/api/model/customerPayoutPaginatePayload.ts create mode 100644 app/lib/api/model/customerPayoutPaginateResponse.ts create mode 100644 app/lib/api/model/customerPayoutPayoutDetails.ts create mode 100644 app/lib/api/model/customerPayoutStatus.ts diff --git a/app/lib/api/bookingShopifyApi.ts b/app/lib/api/bookingShopifyApi.ts index 5a19efa6..a6431417 100644 --- a/app/lib/api/bookingShopifyApi.ts +++ b/app/lib/api/bookingShopifyApi.ts @@ -28,10 +28,16 @@ import type { CustomerLocationUpdateBody, CustomerLocationUpdateResponse, CustomerOrderGetResponse, - CustomerPayoutAccountCreate200, CustomerPayoutAccountCreateBody, - CustomerPayoutAccountDestroy200, - CustomerPayoutAccountGet200, + CustomerPayoutAccountCreateResponse, + CustomerPayoutAccountDestroyResponse, + CustomerPayoutAccountGetResponse, + CustomerPayoutBalanceResponse, + CustomerPayoutGetResponse, + CustomerPayoutLogPaginateParams, + CustomerPayoutLogResponse, + CustomerPayoutPaginateParams, + CustomerPayoutPaginateResponse, CustomerProductCreateVariantBody, CustomerProductCreateVariantResponse, CustomerProductDestroyResponse, @@ -315,6 +321,59 @@ export const getBookingShopifyApi = () => { }); }; + /** + * This endpoint get all payouts + * @summary GET get all payouts using paginate + */ + const customerPayoutPaginate = ( + customerId: string, + params: CustomerPayoutPaginateParams, + ) => { + return queryClient({ + url: `/customer/${customerId}/payouts/paginate`, + method: 'GET', + params, + }); + }; + + /** + * This endpoint get payout balance + * @summary GET get payout balance + */ + const customerPayoutBalance = (customerId: string) => { + return queryClient({ + url: `/customer/${customerId}/payouts/balance`, + method: 'GET', + }); + }; + + /** + * This endpoint get payout + * @summary GET get payout + */ + const customerPayoutGet = (customerId: string, payoutId: string) => { + return queryClient({ + url: `/customer/${customerId}/payout/${payoutId}`, + method: 'GET', + }); + }; + + /** + * This endpoint get all payout logs for specific payout + * @summary GET get all payout logs for specific payout using paginate + */ + const customerPayoutLogPaginate = ( + customerId: string, + payoutId: string, + params: CustomerPayoutLogPaginateParams, + ) => { + return queryClient({ + url: `/customer/${customerId}/payout-logs/${payoutId}/paginate`, + method: 'GET', + params, + }); + }; + /** * This endpoint create new payout account * @summary POST Create payout account @@ -323,7 +382,7 @@ export const getBookingShopifyApi = () => { customerId: string, customerPayoutAccountCreateBody: BodyType, ) => { - return queryClient({ + return queryClient({ url: `/customer/${customerId}/payout-account`, method: 'POST', headers: {'Content-Type': 'application/json'}, @@ -336,7 +395,7 @@ export const getBookingShopifyApi = () => { * @summary GET get payout account */ const customerPayoutAccountGet = (customerId: string) => { - return queryClient({ + return queryClient({ url: `/customer/${customerId}/payout-account`, method: 'GET', }); @@ -347,7 +406,7 @@ export const getBookingShopifyApi = () => { * @summary DEL destroy payout account */ const customerPayoutAccountDestroy = (customerId: string) => { - return queryClient({ + return queryClient({ url: `/customer/${customerId}/payout-account`, method: 'DELETE', }); @@ -899,6 +958,10 @@ export const getBookingShopifyApi = () => { customerLocationCreate, customerLocationList, customerOrderGet, + customerPayoutPaginate, + customerPayoutBalance, + customerPayoutGet, + customerPayoutLogPaginate, customerPayoutAccountCreate, customerPayoutAccountGet, customerPayoutAccountDestroy, @@ -1031,6 +1094,30 @@ export type CustomerOrderGetResult = NonNullable< ReturnType['customerOrderGet']> > >; +export type CustomerPayoutPaginateResult = NonNullable< + Awaited< + ReturnType< + ReturnType['customerPayoutPaginate'] + > + > +>; +export type CustomerPayoutBalanceResult = NonNullable< + Awaited< + ReturnType['customerPayoutBalance']> + > +>; +export type CustomerPayoutGetResult = NonNullable< + Awaited< + ReturnType['customerPayoutGet']> + > +>; +export type CustomerPayoutLogPaginateResult = NonNullable< + Awaited< + ReturnType< + ReturnType['customerPayoutLogPaginate'] + > + > +>; export type CustomerPayoutAccountCreateResult = NonNullable< Awaited< ReturnType< diff --git a/app/lib/api/model/customerPayout.ts b/app/lib/api/model/customerPayout.ts new file mode 100644 index 00000000..a8eca6e7 --- /dev/null +++ b/app/lib/api/model/customerPayout.ts @@ -0,0 +1,19 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayoutPayoutDetails} from './customerPayoutPayoutDetails'; +import type {CustomerPayoutAccountType} from './customerPayoutAccountType'; +import type {CustomerPayoutStatus} from './customerPayoutStatus'; + +export interface CustomerPayout { + amount: number; + currencyCode: string; + customerId: number; + date: Date; + payoutDetails?: CustomerPayoutPayoutDetails; + payoutType?: CustomerPayoutAccountType; + status: CustomerPayoutStatus; +} diff --git a/app/lib/api/model/customerPayoutAccountCreateBody.ts b/app/lib/api/model/customerPayoutAccountCreateBody.ts index 6c16e0c8..cb3f6c1a 100644 --- a/app/lib/api/model/customerPayoutAccountCreateBody.ts +++ b/app/lib/api/model/customerPayoutAccountCreateBody.ts @@ -7,7 +7,7 @@ import type {CustomerPayoutAccountCreateBodyPayoutDetails} from './customerPayoutAccountCreateBodyPayoutDetails'; import type {CustomerPayoutAccountType} from './customerPayoutAccountType'; -export type CustomerPayoutAccountCreateBody = { +export interface CustomerPayoutAccountCreateBody { payoutDetails: CustomerPayoutAccountCreateBodyPayoutDetails; payoutType: CustomerPayoutAccountType; -}; +} diff --git a/app/lib/api/model/customerPayoutAccountGet200Payload.ts b/app/lib/api/model/customerPayoutAccountCreateResponse.ts similarity index 63% rename from app/lib/api/model/customerPayoutAccountGet200Payload.ts rename to app/lib/api/model/customerPayoutAccountCreateResponse.ts index ded55c9f..5c3126b9 100644 --- a/app/lib/api/model/customerPayoutAccountGet200Payload.ts +++ b/app/lib/api/model/customerPayoutAccountCreateResponse.ts @@ -6,4 +6,7 @@ */ import type {CustomerPayoutAccount} from './customerPayoutAccount'; -export type CustomerPayoutAccountGet200Payload = CustomerPayoutAccount | null; +export interface CustomerPayoutAccountCreateResponse { + payload: CustomerPayoutAccount; + success: boolean; +} diff --git a/app/lib/api/model/customerPayoutAccountDestroy200Payload.ts b/app/lib/api/model/customerPayoutAccountDestroy.ts similarity index 74% rename from app/lib/api/model/customerPayoutAccountDestroy200Payload.ts rename to app/lib/api/model/customerPayoutAccountDestroy.ts index 4efbb45a..66e12409 100644 --- a/app/lib/api/model/customerPayoutAccountDestroy200Payload.ts +++ b/app/lib/api/model/customerPayoutAccountDestroy.ts @@ -5,7 +5,7 @@ * OpenAPI spec version: 1.0.0 */ -export type CustomerPayoutAccountDestroy200Payload = { +export interface CustomerPayoutAccountDestroy { acknowledged: boolean; deletedCount: number; -}; +} diff --git a/app/lib/api/model/customerPayoutAccountDestroy200.ts b/app/lib/api/model/customerPayoutAccountDestroy200.ts deleted file mode 100644 index 26460384..00000000 --- a/app/lib/api/model/customerPayoutAccountDestroy200.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Generated by orval v6.25.0 🍺 - * Do not edit manually. - * Booking Shopify Api - * OpenAPI spec version: 1.0.0 - */ -import type {CustomerPayoutAccountDestroy200Payload} from './customerPayoutAccountDestroy200Payload'; - -export type CustomerPayoutAccountDestroy200 = { - payload: CustomerPayoutAccountDestroy200Payload; - success: boolean; -}; diff --git a/app/lib/api/model/customerPayoutAccountDestroyResponse.ts b/app/lib/api/model/customerPayoutAccountDestroyResponse.ts new file mode 100644 index 00000000..7b7727d2 --- /dev/null +++ b/app/lib/api/model/customerPayoutAccountDestroyResponse.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayoutAccountDestroy} from './customerPayoutAccountDestroy'; + +export interface CustomerPayoutAccountDestroyResponse { + payload: CustomerPayoutAccountDestroy; + success: boolean; +} diff --git a/app/lib/api/model/customerPayoutAccountGet200.ts b/app/lib/api/model/customerPayoutAccountGet200.ts deleted file mode 100644 index ba8b23ac..00000000 --- a/app/lib/api/model/customerPayoutAccountGet200.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Generated by orval v6.25.0 🍺 - * Do not edit manually. - * Booking Shopify Api - * OpenAPI spec version: 1.0.0 - */ -import type {CustomerPayoutAccountGet200Payload} from './customerPayoutAccountGet200Payload'; - -export type CustomerPayoutAccountGet200 = { - payload: CustomerPayoutAccountGet200Payload; - success: boolean; -}; diff --git a/app/lib/api/model/customerPayoutAccountCreate200.ts b/app/lib/api/model/customerPayoutAccountGetResponse.ts similarity index 81% rename from app/lib/api/model/customerPayoutAccountCreate200.ts rename to app/lib/api/model/customerPayoutAccountGetResponse.ts index e530a570..64e45906 100644 --- a/app/lib/api/model/customerPayoutAccountCreate200.ts +++ b/app/lib/api/model/customerPayoutAccountGetResponse.ts @@ -6,7 +6,7 @@ */ import type {CustomerPayoutAccount} from './customerPayoutAccount'; -export type CustomerPayoutAccountCreate200 = { +export interface CustomerPayoutAccountGetResponse { payload: CustomerPayoutAccount; success: boolean; -}; +} diff --git a/app/lib/api/model/customerPayoutBalancePayload.ts b/app/lib/api/model/customerPayoutBalancePayload.ts new file mode 100644 index 00000000..553d95c0 --- /dev/null +++ b/app/lib/api/model/customerPayoutBalancePayload.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ + +export interface CustomerPayoutBalancePayload { + totalAmount: number; + totalLineItems: number; + totalShippingAmount: number; +} diff --git a/app/lib/api/model/customerPayoutBalanceResponse.ts b/app/lib/api/model/customerPayoutBalanceResponse.ts new file mode 100644 index 00000000..8d435157 --- /dev/null +++ b/app/lib/api/model/customerPayoutBalanceResponse.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayoutBalancePayload} from './customerPayoutBalancePayload'; + +export interface CustomerPayoutBalanceResponse { + payload: CustomerPayoutBalancePayload; + success: boolean; +} diff --git a/app/lib/api/model/customerPayoutGetResponse.ts b/app/lib/api/model/customerPayoutGetResponse.ts new file mode 100644 index 00000000..2cc6567e --- /dev/null +++ b/app/lib/api/model/customerPayoutGetResponse.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayout} from './customerPayout'; + +export interface CustomerPayoutGetResponse { + payload: CustomerPayout; + success: boolean; +} diff --git a/app/lib/api/model/customerPayoutLogPaginateParams.ts b/app/lib/api/model/customerPayoutLogPaginateParams.ts new file mode 100644 index 00000000..74d888f3 --- /dev/null +++ b/app/lib/api/model/customerPayoutLogPaginateParams.ts @@ -0,0 +1,21 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ + +export type CustomerPayoutLogPaginateParams = { + /** + * The page number + */ + page: string; + /** + * The sort order either asc eller desc = default desc + */ + sortOrder?: string; + /** + * The limit = default to 10 + */ + limit?: string; +}; diff --git a/app/lib/api/model/customerPayoutLogPayload.ts b/app/lib/api/model/customerPayoutLogPayload.ts new file mode 100644 index 00000000..32c54635 --- /dev/null +++ b/app/lib/api/model/customerPayoutLogPayload.ts @@ -0,0 +1,15 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayoutLogPayloadResultsItem} from './customerPayoutLogPayloadResultsItem'; + +export interface CustomerPayoutLogPayload { + currentPage: number; + hasNextPage: boolean; + results: CustomerPayoutLogPayloadResultsItem[]; + totalCount: number; + totalPages: number; +} diff --git a/app/lib/api/model/customerPayoutLogPayloadResultsItem.ts b/app/lib/api/model/customerPayoutLogPayloadResultsItem.ts new file mode 100644 index 00000000..b98f4ab2 --- /dev/null +++ b/app/lib/api/model/customerPayoutLogPayloadResultsItem.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomeBaserOrderLineItem} from './customeBaserOrderLineItem'; +import type {Shipping} from './shipping'; + +export type CustomerPayoutLogPayloadResultsItem = + | CustomeBaserOrderLineItem + | Shipping; diff --git a/app/lib/api/model/customerPayoutLogResponse.ts b/app/lib/api/model/customerPayoutLogResponse.ts new file mode 100644 index 00000000..3e06ec35 --- /dev/null +++ b/app/lib/api/model/customerPayoutLogResponse.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayoutLogPayload} from './customerPayoutLogPayload'; + +export interface CustomerPayoutLogResponse { + payload: CustomerPayoutLogPayload; + success: boolean; +} diff --git a/app/lib/api/model/customerPayoutPaginateParams.ts b/app/lib/api/model/customerPayoutPaginateParams.ts new file mode 100644 index 00000000..24500e71 --- /dev/null +++ b/app/lib/api/model/customerPayoutPaginateParams.ts @@ -0,0 +1,21 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ + +export type CustomerPayoutPaginateParams = { + /** + * The page number + */ + page: string; + /** + * The sort order either asc eller desc = default desc + */ + sortOrder?: string; + /** + * The limit = default to 10 + */ + limit?: string; +}; diff --git a/app/lib/api/model/customerPayoutPaginatePayload.ts b/app/lib/api/model/customerPayoutPaginatePayload.ts new file mode 100644 index 00000000..7e7db353 --- /dev/null +++ b/app/lib/api/model/customerPayoutPaginatePayload.ts @@ -0,0 +1,15 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayout} from './customerPayout'; + +export interface CustomerPayoutPaginatePayload { + currentPage: number; + hasNextPage: boolean; + results: CustomerPayout[]; + totalCount: number; + totalPages: number; +} diff --git a/app/lib/api/model/customerPayoutPaginateResponse.ts b/app/lib/api/model/customerPayoutPaginateResponse.ts new file mode 100644 index 00000000..6261a79f --- /dev/null +++ b/app/lib/api/model/customerPayoutPaginateResponse.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayoutPaginatePayload} from './customerPayoutPaginatePayload'; + +export interface CustomerPayoutPaginateResponse { + payload: CustomerPayoutPaginatePayload; + success: boolean; +} diff --git a/app/lib/api/model/customerPayoutPayoutDetails.ts b/app/lib/api/model/customerPayoutPayoutDetails.ts new file mode 100644 index 00000000..23375177 --- /dev/null +++ b/app/lib/api/model/customerPayoutPayoutDetails.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayoutMobilePay} from './customerPayoutMobilePay'; +import type {CustomerPayoutBankAccount} from './customerPayoutBankAccount'; + +export type CustomerPayoutPayoutDetails = + | CustomerPayoutMobilePay + | CustomerPayoutBankAccount; diff --git a/app/lib/api/model/customerPayoutStatus.ts b/app/lib/api/model/customerPayoutStatus.ts new file mode 100644 index 00000000..8d85d3e8 --- /dev/null +++ b/app/lib/api/model/customerPayoutStatus.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ + +export type CustomerPayoutStatus = + (typeof CustomerPayoutStatus)[keyof typeof CustomerPayoutStatus]; + +// eslint-disable-next-line @typescript-eslint/no-redeclare +export const CustomerPayoutStatus = { + Pending: 'Pending', + Processed: 'Processed', + Failed: 'Failed', +} as const; diff --git a/app/lib/api/model/index.ts b/app/lib/api/model/index.ts index 979763ac..41bda106 100644 --- a/app/lib/api/model/index.ts +++ b/app/lib/api/model/index.ts @@ -76,20 +76,32 @@ export * from './customerOrderAllOf'; export * from './customerOrderGetResponse'; export * from './customerOrderLineItem'; export * from './customerOrderLineItemAllOf'; +export * from './customerPayout'; export * from './customerPayoutAccount'; -export * from './customerPayoutAccountCreate200'; export * from './customerPayoutAccountCreateBody'; export * from './customerPayoutAccountCreateBodyPayoutDetails'; +export * from './customerPayoutAccountCreateResponse'; export * from './customerPayoutAccountCustomerId'; -export * from './customerPayoutAccountDestroy200'; -export * from './customerPayoutAccountDestroy200Payload'; -export * from './customerPayoutAccountGet200'; -export * from './customerPayoutAccountGet200Payload'; +export * from './customerPayoutAccountDestroy'; +export * from './customerPayoutAccountDestroyResponse'; +export * from './customerPayoutAccountGetResponse'; export * from './customerPayoutAccountPayoutDetails'; export * from './customerPayoutAccountType'; +export * from './customerPayoutBalancePayload'; +export * from './customerPayoutBalanceResponse'; export * from './customerPayoutBankAccount'; +export * from './customerPayoutGetResponse'; +export * from './customerPayoutLogPaginateParams'; +export * from './customerPayoutLogPayload'; +export * from './customerPayoutLogPayloadResultsItem'; +export * from './customerPayoutLogResponse'; export * from './customerPayoutMobilePay'; export * from './customerPayoutMobilePayPhoneNumber'; +export * from './customerPayoutPaginateParams'; +export * from './customerPayoutPaginatePayload'; +export * from './customerPayoutPaginateResponse'; +export * from './customerPayoutPayoutDetails'; +export * from './customerPayoutStatus'; export * from './customerProduct'; export * from './customerProductAllOf'; export * from './customerProductBase'; diff --git a/app/lib/api/model/usersListResponsePayload.ts b/app/lib/api/model/usersListResponsePayload.ts index 405442cd..e9ece8c5 100644 --- a/app/lib/api/model/usersListResponsePayload.ts +++ b/app/lib/api/model/usersListResponsePayload.ts @@ -9,5 +9,5 @@ import type {User} from './user'; export type UsersListResponsePayload = { nextCursor?: string; results: User[]; - total: number; + totalCount?: number; }; diff --git a/app/lib/zod/bookingShopifyApi.ts b/app/lib/zod/bookingShopifyApi.ts index 73ba64c1..5f26eb94 100644 --- a/app/lib/zod/bookingShopifyApi.ts +++ b/app/lib/zod/bookingShopifyApi.ts @@ -1839,6 +1839,235 @@ export const customerOrderGetResponse = zod.object({ ), }); +/** + * This endpoint get all payouts + * @summary GET get all payouts using paginate + */ +export const customerPayoutPaginateParams = zod.object({ + customerId: zod.string(), +}); + +export const customerPayoutPaginateQueryParams = zod.object({ + page: zod.string(), + sortOrder: zod.string().optional(), + limit: zod.string().optional(), +}); + +export const customerPayoutPaginateResponse = zod.object({ + success: zod.boolean(), + payload: zod.object({ + results: zod.array( + zod.object({ + customerId: zod.number(), + date: zod.string().datetime(), + amount: zod.number(), + currencyCode: zod.string(), + status: zod.enum(['Pending', 'Processed', 'Failed']), + payoutType: zod.enum(['MOBILE_PAY', 'BANK_ACCOUNT']).optional(), + payoutDetails: zod + .object({ + phoneNumber: zod.string().or(zod.number()), + }) + .or( + zod.object({ + bankName: zod.string(), + regNum: zod.number(), + accountNum: zod.number(), + }), + ) + .optional(), + }), + ), + currentPage: zod.number(), + totalPages: zod.number(), + hasNextPage: zod.boolean(), + totalCount: zod.number(), + }), +}); + +/** + * This endpoint get payout balance + * @summary GET get payout balance + */ +export const customerPayoutBalanceParams = zod.object({ + customerId: zod.string(), +}); + +export const customerPayoutBalanceResponse = zod.object({ + success: zod.boolean(), + payload: zod.object({ + totalAmount: zod.number(), + totalLineItems: zod.number(), + totalShippingAmount: zod.number(), + }), +}); + +/** + * This endpoint get payout + * @summary GET get payout + */ +export const customerPayoutGetParams = zod.object({ + customerId: zod.string(), + payoutId: zod.string(), +}); + +export const customerPayoutGetResponse = zod.object({ + success: zod.boolean(), + payload: zod.object({ + customerId: zod.number(), + date: zod.string().datetime(), + amount: zod.number(), + currencyCode: zod.string(), + status: zod.enum(['Pending', 'Processed', 'Failed']), + payoutType: zod.enum(['MOBILE_PAY', 'BANK_ACCOUNT']).optional(), + payoutDetails: zod + .object({ + phoneNumber: zod.string().or(zod.number()), + }) + .or( + zod.object({ + bankName: zod.string(), + regNum: zod.number(), + accountNum: zod.number(), + }), + ) + .optional(), + }), +}); + +/** + * This endpoint get all payout logs for specific payout + * @summary GET get all payout logs for specific payout using paginate + */ +export const customerPayoutLogPaginateParams = zod.object({ + customerId: zod.string(), + payoutId: zod.string(), +}); + +export const customerPayoutLogPaginateQueryParams = zod.object({ + page: zod.string(), + sortOrder: zod.string().optional(), + limit: zod.string().optional(), +}); + +export const customerPayoutLogPaginateResponse = zod.object({ + success: zod.boolean(), + payload: zod.object({ + results: zod.array( + zod + .object({ + id: zod.number(), + admin_graphql_api_id: zod.string(), + fulfillable_quantity: zod.number(), + fulfillment_service: zod.string(), + fulfillment_status: zod.string().optional(), + gift_card: zod.boolean(), + grams: zod.number(), + name: zod.string(), + price: zod.string(), + price_set: zod.object({ + shop_money: zod.object({ + amount: zod.string(), + currency_code: zod.string(), + }), + presentment_money: zod.object({ + amount: zod.string(), + currency_code: zod.string(), + }), + }), + product_exists: zod.boolean(), + product_id: zod.number(), + properties: zod.object({ + customer_id: zod.number(), + from: zod.string(), + to: zod.string(), + locationId: zod.string(), + groupId: zod.string(), + shippingId: zod.string().optional(), + }), + quantity: zod.number(), + requires_shipping: zod.boolean(), + sku: zod.string().optional(), + taxable: zod.boolean(), + title: zod.string(), + total_discount: zod.string(), + total_discount_set: zod.object({ + shop_money: zod.object({ + amount: zod.string(), + currency_code: zod.string(), + }), + presentment_money: zod.object({ + amount: zod.string(), + currency_code: zod.string(), + }), + }), + variant_id: zod.number(), + variant_inventory_management: zod.string().optional(), + variant_title: zod.string().optional(), + vendor: zod.string().optional(), + }) + .or( + zod + .object({ + duration: zod.object({ + text: zod.string(), + value: zod.number(), + }), + distance: zod.object({ + text: zod.string(), + value: zod.number(), + }), + }) + .and( + zod.object({ + destination: zod.object({ + name: zod.string(), + fullAddress: zod.string(), + }), + cost: zod.object({ + currency: zod.string(), + value: zod.number(), + }), + }), + ) + .and( + zod.object({ + _id: zod.string(), + location: zod.string(), + origin: zod + .object({ + locationType: zod.enum(['origin', 'destination']), + customerId: zod.string(), + originType: zod.enum(['home', 'commercial']), + name: zod.string(), + fullAddress: zod.string(), + }) + .and( + zod.object({ + _id: zod.string(), + geoLocation: zod.object({ + type: zod.enum(['Point']), + coordinates: zod.array(zod.number()), + }), + distanceForFree: zod.number(), + distanceHourlyRate: zod.number(), + fixedRatePerKm: zod.number(), + minDriveDistance: zod.number(), + maxDriveDistance: zod.number(), + startFee: zod.number(), + }), + ), + }), + ), + ), + ), + currentPage: zod.number(), + totalPages: zod.number(), + hasNextPage: zod.boolean(), + totalCount: zod.number(), + }), +}); + /** * This endpoint create new payout account * @summary POST Create payout account @@ -1891,23 +2120,21 @@ export const customerPayoutAccountGetParams = zod.object({ export const customerPayoutAccountGetResponse = zod.object({ success: zod.boolean(), - payload: zod - .object({ - customerId: zod.string().or(zod.number()), - payoutType: zod.enum(['MOBILE_PAY', 'BANK_ACCOUNT']), - payoutDetails: zod - .object({ - phoneNumber: zod.string().or(zod.number()), - }) - .or( - zod.object({ - bankName: zod.string(), - regNum: zod.number(), - accountNum: zod.number(), - }), - ), - }) - .nullable(), + payload: zod.object({ + customerId: zod.string().or(zod.number()), + payoutType: zod.enum(['MOBILE_PAY', 'BANK_ACCOUNT']), + payoutDetails: zod + .object({ + phoneNumber: zod.string().or(zod.number()), + }) + .or( + zod.object({ + bankName: zod.string(), + regNum: zod.number(), + accountNum: zod.number(), + }), + ), + }), }); /** @@ -3878,7 +4105,7 @@ export const usersListResponse = zod.object({ }), }), ), - total: zod.number(), + totalCount: zod.number().optional(), }), }); diff --git a/openapi.yaml b/openapi.yaml index e171764f..6be48eaf 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -138,6 +138,63 @@ components: enum: - MOBILE_PAY - BANK_ACCOUNT + CustomerPayoutAccountCreateBody: + type: object + properties: + payoutType: + $ref: '#/components/schemas/CustomerPayoutAccountType' + payoutDetails: + oneOf: + - $ref: '#/components/schemas/CustomerPayoutMobilePay' + - $ref: '#/components/schemas/CustomerPayoutBankAccount' + required: + - payoutType + - payoutDetails + CustomerPayoutAccountCreateResponse: + type: object + properties: + success: + type: boolean + example: true + payload: + $ref: '#/components/schemas/CustomerPayoutAccount' + required: + - success + - payload + CustomerPayoutAccountDestroy: + type: object + properties: + deletedCount: + type: number + acknowledged: + type: boolean + required: + - deletedCount + - acknowledged + CustomerPayoutAccountDestroyResponse: + type: object + properties: + success: + type: boolean + example: true + payload: + $ref: '#/components/schemas/CustomerPayoutAccountDestroy' + required: + - success + - payload + CustomerPayoutAccountGetResponse: + type: object + properties: + success: + type: boolean + example: true + payload: + allOf: + - $ref: '#/components/schemas/CustomerPayoutAccount' + nullable: true + required: + - success + - payload CustomerPayoutMobilePay: type: object properties: @@ -1284,6 +1341,139 @@ components: required: - success - payload + CustomerPayout: + type: object + properties: + customerId: + type: number + date: + type: string + format: date-time + amount: + type: number + format: double + currencyCode: + type: string + example: DKK + status: + type: string + enum: + - Pending + - Processed + - Failed + payoutType: + $ref: '#/components/schemas/CustomerPayoutAccountType' + payoutDetails: + oneOf: + - $ref: '#/components/schemas/CustomerPayoutMobilePay' + - $ref: '#/components/schemas/CustomerPayoutBankAccount' + required: + - customerId + - date + - amount + - currencyCode + - status + CustomerPayoutBalancePayload: + type: object + properties: + totalAmount: + type: number + totalLineItems: + type: number + totalShippingAmount: + type: number + required: + - totalAmount + - totalLineItems + - totalShippingAmount + CustomerPayoutBalanceResponse: + type: object + properties: + success: + type: boolean + example: true + payload: + $ref: '#/components/schemas/CustomerPayoutBalancePayload' + required: + - success + - payload + CustomerPayoutGetResponse: + type: object + properties: + success: + type: boolean + example: true + payload: + $ref: '#/components/schemas/CustomerPayout' + required: + - success + - payload + CustomerPayoutPaginatePayload: + type: object + properties: + results: + type: array + items: + $ref: '#/components/schemas/CustomerPayout' + currentPage: + type: number + totalPages: + type: number + hasNextPage: + type: boolean + totalCount: + type: number + required: + - results + - currentPage + - totalPages + - hasNextPage + - totalCount + CustomerPayoutPaginateResponse: + type: object + properties: + success: + type: boolean + example: true + payload: + $ref: '#/components/schemas/CustomerPayoutPaginatePayload' + required: + - success + - payload + CustomerPayoutLogPayload: + type: object + properties: + results: + type: array + items: + oneOf: + - $ref: '#/components/schemas/CustomeBaserOrderLineItem' + - $ref: '#/components/schemas/Shipping' + currentPage: + type: number + totalPages: + type: number + hasNextPage: + type: boolean + totalCount: + type: number + required: + - results + - currentPage + - totalPages + - hasNextPage + - totalCount + CustomerPayoutLogResponse: + type: object + properties: + success: + type: boolean + example: true + payload: + $ref: '#/components/schemas/CustomerPayoutLogPayload' + required: + - success + - payload CustomerBooking: allOf: - $ref: '#/components/schemas/CustomerBaseOrder' @@ -2066,7 +2256,7 @@ components: type: array items: $ref: '#/components/schemas/User' - total: + totalCount: type: number required: - results @@ -3188,6 +3378,170 @@ paths: '404': $ref: '#/components/responses/NotFoundResponse' security: [] + '/customer/{customerId}/payouts/paginate': + get: + parameters: + - name: customerId + in: path + description: The ID of the customerId + required: true + schema: + type: string + - name: page + in: query + description: The page number + required: true + schema: + type: string + - name: sortOrder + in: query + description: The sort order either asc eller desc = default desc + schema: + type: string + - name: limit + in: query + description: The limit = default to 10 + schema: + type: string + tags: + - CustomerPayout + operationId: customerPayoutPaginate + summary: GET get all payouts using paginate + description: This endpoint get all payouts + responses: + '200': + description: Response with payouts payload + content: + application/json: + schema: + $ref: '#/components/schemas/CustomerPayoutPaginateResponse' + '400': + $ref: '#/components/responses/BadResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + security: [] + '/customer/{customerId}/payouts/balance': + get: + parameters: + - name: customerId + in: path + description: The ID of the customerId + required: true + schema: + type: string + tags: + - CustomerPayout + operationId: customerPayoutBalance + summary: GET get payout balance + description: This endpoint get payout balance + responses: + '200': + description: Response with payout balance payload + content: + application/json: + schema: + $ref: '#/components/schemas/CustomerPayoutBalanceResponse' + '400': + $ref: '#/components/responses/BadResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + security: [] + '/customer/{customerId}/payout/{payoutId}': + get: + parameters: + - name: customerId + in: path + description: The ID of the customerId + required: true + schema: + type: string + - name: payoutId + in: path + description: The ID of the payoudId + required: true + schema: + type: string + tags: + - CustomerPayout + operationId: customerPayoutGet + summary: GET get payout + description: This endpoint get payout + responses: + '200': + description: Response with payout payload + content: + application/json: + schema: + $ref: '#/components/schemas/CustomerPayoutGetResponse' + '400': + $ref: '#/components/responses/BadResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + security: [] + '/customer/{customerId}/payout-logs/{payoutId}/paginate': + get: + parameters: + - name: customerId + in: path + description: The ID of the customerId + required: true + schema: + type: string + - name: payoutId + in: path + description: The ID of the payoutId + required: true + schema: + type: string + - name: page + in: query + description: The page number + required: true + schema: + type: string + - name: sortOrder + in: query + description: The sort order either asc eller desc = default desc + schema: + type: string + - name: limit + in: query + description: The limit = default to 10 + schema: + type: string + tags: + - CustomerPayoutLog + operationId: customerPayoutLogPaginate + summary: GET get all payout logs for specific payout using paginate + description: This endpoint get all payout logs for specific payout + responses: + '200': + description: Response with payouts payload + content: + application/json: + schema: + $ref: '#/components/schemas/CustomerPayoutLogResponse' + '400': + $ref: '#/components/responses/BadResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + security: [] '/customer/{customerId}/payout-account': post: parameters: @@ -3207,33 +3561,14 @@ paths: content: application/json: schema: - type: object - properties: - payoutType: - $ref: '#/components/schemas/CustomerPayoutAccountType' - payoutDetails: - oneOf: - - $ref: '#/components/schemas/CustomerPayoutMobilePay' - - $ref: '#/components/schemas/CustomerPayoutBankAccount' - required: - - payoutType - - payoutDetails + $ref: '#/components/schemas/CustomerPayoutAccountCreateBody' responses: '200': description: Response with payout account payload content: application/json: schema: - type: object - properties: - success: - type: boolean - example: true - payload: - $ref: '#/components/schemas/CustomerPayoutAccount' - required: - - success - - payload + $ref: '#/components/schemas/CustomerPayoutAccountCreateResponse' '400': $ref: '#/components/responses/BadResponse' '401': @@ -3262,18 +3597,7 @@ paths: content: application/json: schema: - type: object - properties: - success: - type: boolean - example: true - payload: - allOf: - - $ref: '#/components/schemas/CustomerPayoutAccount' - nullable: true - required: - - success - - payload + $ref: '#/components/schemas/CustomerPayoutAccountGetResponse' '400': $ref: '#/components/responses/BadResponse' '401': @@ -3302,24 +3626,7 @@ paths: content: application/json: schema: - type: object - properties: - success: - type: boolean - example: true - payload: - type: object - properties: - deletedCount: - type: number - acknowledged: - type: boolean - required: - - deletedCount - - acknowledged - required: - - success - - payload + $ref: '#/components/schemas/CustomerPayoutAccountDestroyResponse' '400': $ref: '#/components/responses/BadResponse' '401': From edb0bcd5d20e1834fd578d86460b91af6c7a10fb Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Mon, 1 Apr 2024 03:13:07 +0200 Subject: [PATCH 2/7] Refactor payout loading to use defer and Suspense for async data fetching --- .../($locale).account.payouts._index.tsx | 206 ++++++++++++------ 1 file changed, 138 insertions(+), 68 deletions(-) diff --git a/app/routes/($locale).account.payouts._index.tsx b/app/routes/($locale).account.payouts._index.tsx index 9013aa6e..efe325a2 100644 --- a/app/routes/($locale).account.payouts._index.tsx +++ b/app/routes/($locale).account.payouts._index.tsx @@ -8,21 +8,34 @@ import { Text, Title, } from '@mantine/core'; -import {Form, Link, useLoaderData} from '@remix-run/react'; -import {json, type LoaderFunctionArgs} from '@shopify/remix-oxygen'; +import {Await, Form, Link, useLoaderData} from '@remix-run/react'; +import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen'; import {format} from 'date-fns'; import {da} from 'date-fns/locale'; +import {Suspense} from 'react'; import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi'; +import type { + CustomerPayoutAccountGetResponse, + CustomerPayoutBalanceResponse, +} from '~/lib/api/model'; import {getCustomer} from '~/lib/get-customer'; import {isMobilePay} from './($locale).account.payouts'; export async function loader({context}: LoaderFunctionArgs) { const customer = await getCustomer({context}); - const {payload} = await getBookingShopifyApi().customerPayoutAccountGet( + const payoutAccount = getBookingShopifyApi().customerPayoutAccountGet( customer.id, ); - return json({payoutAccount: payload}); + const payoutBalance = getBookingShopifyApi().customerPayoutBalance( + customer.id, + ); + + const payouts = getBookingShopifyApi().customerPayoutPaginate(customer.id, { + page: '1', + }); + + return defer({payoutAccount, payoutBalance, payouts}); } const elements = [ @@ -35,62 +48,12 @@ const elements = [ export default function AccountPayoutsIndex() { const data = useLoaderData(); - const rows = elements.map((element) => ( - - {format(new Date(), 'yyyy-MM-dd', {locale: da})} - - Overført - - 0.00 DKK - - )); return ( - - - {data.payoutAccount ? ( - <> - {isMobilePay(data.payoutAccount.payoutDetails) ? ( - <> - MobilePay overførsel - {data.payoutAccount.payoutDetails.phoneNumber} - - ) : ( - <> - Bank overførsel - {data.payoutAccount.payoutDetails.bankName} - - {data.payoutAccount.payoutDetails.regNum} /{' '} - {data.payoutAccount.payoutDetails.accountNum} - - - )} -
- -
- - ) : ( - <> - - For at kunne modtag betaling, skal du vælge overførselsmetode - du ønsker - - - - )} -
-
+ +
@@ -98,18 +61,125 @@ export default function AccountPayoutsIndex() { Listen af alle udbetalinger der er foretagt
- - - - - Dato - Status - Beløb - - - {rows} -
-
+ asd}> + + {({payload}) => { + return ( + + + + + Dato + Status + Beløb + + + + {payload.totalCount > 0 ? ( + + {payload.results.map((payout) => ( + + + {format(new Date(), 'yyyy-MM-dd', {locale: da})} + + + {payout.status} + + {payout.amount} DKK + + ))} + + ) : ( + + + + Der er ikke oprettet udbetalinger endnu! + + + + )} +
+
+ ); + }} +
+
); } + +const PayoutBalance = ({ + payoutBalance, +}: { + payoutBalance: Promise; +}) => { + return ( + asd}> + + {({payload}) => { + return ( + + + Balance + DKK {payload.totalAmount} + + + ); + }} + + + ); +}; + +const PayoutAccount = ({ + payoutAccount, +}: { + payoutAccount: Promise; +}) => { + return ( + asd}> + + {({payload}) => { + return ( + + + {payload ? ( + <> + {isMobilePay(payload.payoutDetails) ? ( + <> + MobilePay overførsel + {payload.payoutDetails.phoneNumber} + + ) : ( + <> + Bank overførsel + {payload.payoutDetails.bankName} + + {payload.payoutDetails.regNum} /{' '} + {payload.payoutDetails.accountNum} + + + )} +
+ +
+ + ) : ( + <> + Overførselsmetode + Du har ikke valgt en overførselsmetode. + + + )} +
+
+ ); + }} +
+
+ ); +}; From ee71323a22ca8f96646a2a8436991144c152c250 Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Mon, 1 Apr 2024 06:06:18 +0200 Subject: [PATCH 3/7] update api --- app/lib/api/bookingShopifyApi.ts | 18 ++ app/lib/api/model/customerPayout.ts | 4 +- .../api/model/customerPayoutCreateResponse.ts | 12 + app/lib/api/model/customerPayoutLog.ts | 18 ++ app/lib/api/model/customerPayoutLogPayload.ts | 4 +- ... => customerPayoutLogReferenceDocument.ts} | 2 +- app/lib/api/model/customerPayoutLogType.ts | 15 ++ app/lib/api/model/index.ts | 5 +- app/lib/zod/bookingShopifyApi.ts | 240 ++++++++++-------- openapi.yaml | 83 +++++- 10 files changed, 289 insertions(+), 112 deletions(-) create mode 100644 app/lib/api/model/customerPayoutCreateResponse.ts create mode 100644 app/lib/api/model/customerPayoutLog.ts rename app/lib/api/model/{customerPayoutLogPayloadResultsItem.ts => customerPayoutLogReferenceDocument.ts} (85%) create mode 100644 app/lib/api/model/customerPayoutLogType.ts diff --git a/app/lib/api/bookingShopifyApi.ts b/app/lib/api/bookingShopifyApi.ts index a6431417..ee57f9d3 100644 --- a/app/lib/api/bookingShopifyApi.ts +++ b/app/lib/api/bookingShopifyApi.ts @@ -33,6 +33,7 @@ import type { CustomerPayoutAccountDestroyResponse, CustomerPayoutAccountGetResponse, CustomerPayoutBalanceResponse, + CustomerPayoutCreateResponse, CustomerPayoutGetResponse, CustomerPayoutLogPaginateParams, CustomerPayoutLogResponse, @@ -358,6 +359,17 @@ export const getBookingShopifyApi = () => { }); }; + /** + * This endpoint create payout + * @summary POST Create payout + */ + const customerPayoutCreate = (customerId: string) => { + return queryClient({ + url: `/customer/${customerId}/payout/create`, + method: 'POST', + }); + }; + /** * This endpoint get all payout logs for specific payout * @summary GET get all payout logs for specific payout using paginate @@ -961,6 +973,7 @@ export const getBookingShopifyApi = () => { customerPayoutPaginate, customerPayoutBalance, customerPayoutGet, + customerPayoutCreate, customerPayoutLogPaginate, customerPayoutAccountCreate, customerPayoutAccountGet, @@ -1111,6 +1124,11 @@ export type CustomerPayoutGetResult = NonNullable< ReturnType['customerPayoutGet']> > >; +export type CustomerPayoutCreateResult = NonNullable< + Awaited< + ReturnType['customerPayoutCreate']> + > +>; export type CustomerPayoutLogPaginateResult = NonNullable< Awaited< ReturnType< diff --git a/app/lib/api/model/customerPayout.ts b/app/lib/api/model/customerPayout.ts index a8eca6e7..8209c47d 100644 --- a/app/lib/api/model/customerPayout.ts +++ b/app/lib/api/model/customerPayout.ts @@ -9,10 +9,10 @@ import type {CustomerPayoutAccountType} from './customerPayoutAccountType'; import type {CustomerPayoutStatus} from './customerPayoutStatus'; export interface CustomerPayout { + _id?: string; amount: number; currencyCode: string; - customerId: number; - date: Date; + date: string; payoutDetails?: CustomerPayoutPayoutDetails; payoutType?: CustomerPayoutAccountType; status: CustomerPayoutStatus; diff --git a/app/lib/api/model/customerPayoutCreateResponse.ts b/app/lib/api/model/customerPayoutCreateResponse.ts new file mode 100644 index 00000000..8057050a --- /dev/null +++ b/app/lib/api/model/customerPayoutCreateResponse.ts @@ -0,0 +1,12 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayout} from './customerPayout'; + +export interface CustomerPayoutCreateResponse { + payload: CustomerPayout; + success: boolean; +} diff --git a/app/lib/api/model/customerPayoutLog.ts b/app/lib/api/model/customerPayoutLog.ts new file mode 100644 index 00000000..7fd84b9c --- /dev/null +++ b/app/lib/api/model/customerPayoutLog.ts @@ -0,0 +1,18 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ +import type {CustomerPayoutLogReferenceDocument} from './customerPayoutLogReferenceDocument'; +import type {CustomerPayoutLogType} from './customerPayoutLogType'; + +export interface CustomerPayoutLog { + _id: string; + createdAt: string; + customerId: number; + payout: string; + referenceDocument: CustomerPayoutLogReferenceDocument; + referenceId: string; + referenceType: CustomerPayoutLogType; +} diff --git a/app/lib/api/model/customerPayoutLogPayload.ts b/app/lib/api/model/customerPayoutLogPayload.ts index 32c54635..14c75a77 100644 --- a/app/lib/api/model/customerPayoutLogPayload.ts +++ b/app/lib/api/model/customerPayoutLogPayload.ts @@ -4,12 +4,12 @@ * Booking Shopify Api * OpenAPI spec version: 1.0.0 */ -import type {CustomerPayoutLogPayloadResultsItem} from './customerPayoutLogPayloadResultsItem'; +import type {CustomerPayoutLog} from './customerPayoutLog'; export interface CustomerPayoutLogPayload { currentPage: number; hasNextPage: boolean; - results: CustomerPayoutLogPayloadResultsItem[]; + results: CustomerPayoutLog[]; totalCount: number; totalPages: number; } diff --git a/app/lib/api/model/customerPayoutLogPayloadResultsItem.ts b/app/lib/api/model/customerPayoutLogReferenceDocument.ts similarity index 85% rename from app/lib/api/model/customerPayoutLogPayloadResultsItem.ts rename to app/lib/api/model/customerPayoutLogReferenceDocument.ts index b98f4ab2..cc592416 100644 --- a/app/lib/api/model/customerPayoutLogPayloadResultsItem.ts +++ b/app/lib/api/model/customerPayoutLogReferenceDocument.ts @@ -7,6 +7,6 @@ import type {CustomeBaserOrderLineItem} from './customeBaserOrderLineItem'; import type {Shipping} from './shipping'; -export type CustomerPayoutLogPayloadResultsItem = +export type CustomerPayoutLogReferenceDocument = | CustomeBaserOrderLineItem | Shipping; diff --git a/app/lib/api/model/customerPayoutLogType.ts b/app/lib/api/model/customerPayoutLogType.ts new file mode 100644 index 00000000..3a041a4e --- /dev/null +++ b/app/lib/api/model/customerPayoutLogType.ts @@ -0,0 +1,15 @@ +/** + * Generated by orval v6.25.0 🍺 + * Do not edit manually. + * Booking Shopify Api + * OpenAPI spec version: 1.0.0 + */ + +export type CustomerPayoutLogType = + (typeof CustomerPayoutLogType)[keyof typeof CustomerPayoutLogType]; + +// eslint-disable-next-line @typescript-eslint/no-redeclare +export const CustomerPayoutLogType = { + Shipping: 'Shipping', + LineItem: 'LineItem', +} as const; diff --git a/app/lib/api/model/index.ts b/app/lib/api/model/index.ts index 41bda106..578ce986 100644 --- a/app/lib/api/model/index.ts +++ b/app/lib/api/model/index.ts @@ -90,11 +90,14 @@ export * from './customerPayoutAccountType'; export * from './customerPayoutBalancePayload'; export * from './customerPayoutBalanceResponse'; export * from './customerPayoutBankAccount'; +export * from './customerPayoutCreateResponse'; export * from './customerPayoutGetResponse'; +export * from './customerPayoutLog'; export * from './customerPayoutLogPaginateParams'; export * from './customerPayoutLogPayload'; -export * from './customerPayoutLogPayloadResultsItem'; +export * from './customerPayoutLogReferenceDocument'; export * from './customerPayoutLogResponse'; +export * from './customerPayoutLogType'; export * from './customerPayoutMobilePay'; export * from './customerPayoutMobilePayPhoneNumber'; export * from './customerPayoutPaginateParams'; diff --git a/app/lib/zod/bookingShopifyApi.ts b/app/lib/zod/bookingShopifyApi.ts index 5f26eb94..186a0c7c 100644 --- a/app/lib/zod/bookingShopifyApi.ts +++ b/app/lib/zod/bookingShopifyApi.ts @@ -1858,8 +1858,8 @@ export const customerPayoutPaginateResponse = zod.object({ payload: zod.object({ results: zod.array( zod.object({ - customerId: zod.number(), - date: zod.string().datetime(), + _id: zod.string().optional(), + date: zod.string(), amount: zod.number(), currencyCode: zod.string(), status: zod.enum(['Pending', 'Processed', 'Failed']), @@ -1914,8 +1914,40 @@ export const customerPayoutGetParams = zod.object({ export const customerPayoutGetResponse = zod.object({ success: zod.boolean(), payload: zod.object({ - customerId: zod.number(), - date: zod.string().datetime(), + _id: zod.string().optional(), + date: zod.string(), + amount: zod.number(), + currencyCode: zod.string(), + status: zod.enum(['Pending', 'Processed', 'Failed']), + payoutType: zod.enum(['MOBILE_PAY', 'BANK_ACCOUNT']).optional(), + payoutDetails: zod + .object({ + phoneNumber: zod.string().or(zod.number()), + }) + .or( + zod.object({ + bankName: zod.string(), + regNum: zod.number(), + accountNum: zod.number(), + }), + ) + .optional(), + }), +}); + +/** + * This endpoint create payout + * @summary POST Create payout + */ +export const customerPayoutCreateParams = zod.object({ + customerId: zod.string(), +}); + +export const customerPayoutCreateResponse = zod.object({ + success: zod.boolean(), + payload: zod.object({ + _id: zod.string().optional(), + date: zod.string(), amount: zod.number(), currencyCode: zod.string(), status: zod.enum(['Pending', 'Processed', 'Failed']), @@ -1954,112 +1986,120 @@ export const customerPayoutLogPaginateResponse = zod.object({ success: zod.boolean(), payload: zod.object({ results: zod.array( - zod - .object({ - id: zod.number(), - admin_graphql_api_id: zod.string(), - fulfillable_quantity: zod.number(), - fulfillment_service: zod.string(), - fulfillment_status: zod.string().optional(), - gift_card: zod.boolean(), - grams: zod.number(), - name: zod.string(), - price: zod.string(), - price_set: zod.object({ - shop_money: zod.object({ - amount: zod.string(), - currency_code: zod.string(), - }), - presentment_money: zod.object({ - amount: zod.string(), - currency_code: zod.string(), - }), - }), - product_exists: zod.boolean(), - product_id: zod.number(), - properties: zod.object({ - customer_id: zod.number(), - from: zod.string(), - to: zod.string(), - locationId: zod.string(), - groupId: zod.string(), - shippingId: zod.string().optional(), - }), - quantity: zod.number(), - requires_shipping: zod.boolean(), - sku: zod.string().optional(), - taxable: zod.boolean(), - title: zod.string(), - total_discount: zod.string(), - total_discount_set: zod.object({ - shop_money: zod.object({ - amount: zod.string(), - currency_code: zod.string(), + zod.object({ + _id: zod.string(), + customerId: zod.number(), + referenceType: zod.enum(['Shipping', 'LineItem']), + referenceId: zod.string(), + payout: zod.string(), + createdAt: zod.string(), + referenceDocument: zod + .object({ + id: zod.number(), + admin_graphql_api_id: zod.string(), + fulfillable_quantity: zod.number(), + fulfillment_service: zod.string(), + fulfillment_status: zod.string().optional(), + gift_card: zod.boolean(), + grams: zod.number(), + name: zod.string(), + price: zod.string(), + price_set: zod.object({ + shop_money: zod.object({ + amount: zod.string(), + currency_code: zod.string(), + }), + presentment_money: zod.object({ + amount: zod.string(), + currency_code: zod.string(), + }), }), - presentment_money: zod.object({ - amount: zod.string(), - currency_code: zod.string(), + product_exists: zod.boolean(), + product_id: zod.number(), + properties: zod.object({ + customer_id: zod.number(), + from: zod.string(), + to: zod.string(), + locationId: zod.string(), + groupId: zod.string(), + shippingId: zod.string().optional(), }), - }), - variant_id: zod.number(), - variant_inventory_management: zod.string().optional(), - variant_title: zod.string().optional(), - vendor: zod.string().optional(), - }) - .or( - zod - .object({ - duration: zod.object({ - text: zod.string(), - value: zod.number(), + quantity: zod.number(), + requires_shipping: zod.boolean(), + sku: zod.string().optional(), + taxable: zod.boolean(), + title: zod.string(), + total_discount: zod.string(), + total_discount_set: zod.object({ + shop_money: zod.object({ + amount: zod.string(), + currency_code: zod.string(), }), - distance: zod.object({ - text: zod.string(), - value: zod.number(), + presentment_money: zod.object({ + amount: zod.string(), + currency_code: zod.string(), }), - }) - .and( - zod.object({ - destination: zod.object({ - name: zod.string(), - fullAddress: zod.string(), + }), + variant_id: zod.number(), + variant_inventory_management: zod.string().optional(), + variant_title: zod.string().optional(), + vendor: zod.string().optional(), + }) + .or( + zod + .object({ + duration: zod.object({ + text: zod.string(), + value: zod.number(), }), - cost: zod.object({ - currency: zod.string(), + distance: zod.object({ + text: zod.string(), value: zod.number(), }), - }), - ) - .and( - zod.object({ - _id: zod.string(), - location: zod.string(), - origin: zod - .object({ - locationType: zod.enum(['origin', 'destination']), - customerId: zod.string(), - originType: zod.enum(['home', 'commercial']), + }) + .and( + zod.object({ + destination: zod.object({ name: zod.string(), fullAddress: zod.string(), - }) - .and( - zod.object({ - _id: zod.string(), - geoLocation: zod.object({ - type: zod.enum(['Point']), - coordinates: zod.array(zod.number()), + }), + cost: zod.object({ + currency: zod.string(), + value: zod.number(), + }), + }), + ) + .and( + zod.object({ + _id: zod.string(), + location: zod.string(), + origin: zod + .object({ + locationType: zod.enum(['origin', 'destination']), + customerId: zod.string(), + originType: zod.enum(['home', 'commercial']), + name: zod.string(), + fullAddress: zod.string(), + }) + .and( + zod.object({ + _id: zod.string(), + geoLocation: zod.object({ + type: zod.enum(['Point']), + coordinates: zod.array(zod.number()), + }), + distanceForFree: zod.number(), + distanceHourlyRate: zod.number(), + fixedRatePerKm: zod.number(), + minDriveDistance: zod.number(), + maxDriveDistance: zod.number(), + startFee: zod.number(), }), - distanceForFree: zod.number(), - distanceHourlyRate: zod.number(), - fixedRatePerKm: zod.number(), - minDriveDistance: zod.number(), - maxDriveDistance: zod.number(), - startFee: zod.number(), - }), - ), - }), - ), - ), + ), + }), + ), + ), + }), ), currentPage: zod.number(), totalPages: zod.number(), diff --git a/openapi.yaml b/openapi.yaml index 6be48eaf..318b7cee 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1344,11 +1344,10 @@ components: CustomerPayout: type: object properties: - customerId: - type: number + _id: + type: string date: type: string - format: date-time amount: type: number format: double @@ -1440,15 +1439,57 @@ components: required: - success - payload + CustomerPayoutCreateResponse: + type: object + properties: + success: + type: boolean + example: true + payload: + $ref: '#/components/schemas/CustomerPayout' + required: + - success + - payload + CustomerPayoutLogType: + type: string + enum: + - Shipping + - LineItem + CustomerPayoutLog: + type: object + properties: + _id: + type: string + customerId: + type: number + referenceType: + $ref: '#/components/schemas/CustomerPayoutLogType' + referenceId: + type: string + payout: + type: string + format: objectId + createdAt: + type: string + referenceDocument: + oneOf: + - $ref: '#/components/schemas/CustomeBaserOrderLineItem' + - $ref: '#/components/schemas/Shipping' + required: + - _id + - customerId + - referenceType + - referenceId + - referenceDocument + - payout + - createdAt CustomerPayoutLogPayload: type: object properties: results: type: array items: - oneOf: - - $ref: '#/components/schemas/CustomeBaserOrderLineItem' - - $ref: '#/components/schemas/Shipping' + $ref: '#/components/schemas/CustomerPayoutLog' currentPage: type: number totalPages: @@ -3490,6 +3531,36 @@ paths: '404': $ref: '#/components/responses/NotFoundResponse' security: [] + '/customer/{customerId}/payout/create': + post: + parameters: + - name: customerId + in: path + description: The ID of the customerId + required: true + schema: + type: string + tags: + - CustomerPayout + operationId: customerPayoutCreate + summary: POST Create payout + description: This endpoint create payout + responses: + '200': + description: Response with payout payload + content: + application/json: + schema: + $ref: '#/components/schemas/CustomerPayoutCreateResponse' + '400': + $ref: '#/components/responses/BadResponse' + '401': + $ref: '#/components/responses/UnauthorizedResponse' + '403': + $ref: '#/components/responses/ForbiddenResponse' + '404': + $ref: '#/components/responses/NotFoundResponse' + security: [] '/customer/{customerId}/payout-logs/{payoutId}/paginate': get: parameters: From 01dffd8d5a3a8ba35b614bf08188909190bee94b Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Mon, 1 Apr 2024 06:06:46 +0200 Subject: [PATCH 4/7] Increase Skeleton height in Hero.tsx and add new payouts details route and view logic --- app/components/Hero.tsx | 2 +- app/routes/($locale).account.payouts.$id.tsx | 158 ++++++++++++++++++ .../($locale).account.payouts._index.tsx | 27 +-- 3 files changed, 175 insertions(+), 12 deletions(-) create mode 100644 app/routes/($locale).account.payouts.$id.tsx diff --git a/app/components/Hero.tsx b/app/components/Hero.tsx index 9e98d80b..e75f0e59 100644 --- a/app/components/Hero.tsx +++ b/app/components/Hero.tsx @@ -66,7 +66,7 @@ export function Hero({ - }> + }> {({payload}) => } diff --git a/app/routes/($locale).account.payouts.$id.tsx b/app/routes/($locale).account.payouts.$id.tsx new file mode 100644 index 00000000..6066661a --- /dev/null +++ b/app/routes/($locale).account.payouts.$id.tsx @@ -0,0 +1,158 @@ +import {Card, Stack, Table, Text} from '@mantine/core'; +import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen'; +import {getCustomer} from '~/lib/get-customer'; + +import {Await, useLoaderData} from '@remix-run/react'; + +import {Suspense} from 'react'; +import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi'; +import type { + CustomerPayoutGetResponse, + CustomerPayoutLogReferenceDocument, + CustomerPayoutLogResponse, + Shipping, +} from '~/lib/api/model'; +import {isMobilePay} from './($locale).account.payouts'; + +export function isShipping( + details: CustomerPayoutLogReferenceDocument, +): details is Shipping { + return (details as Shipping).cost !== undefined; +} + +export async function loader({context, params}: LoaderFunctionArgs) { + const customer = await getCustomer({context}); + const {id} = params; + + const payout = getBookingShopifyApi().customerPayoutGet( + customer.id, + id || '', + ); + + const payoutLogs = getBookingShopifyApi().customerPayoutLogPaginate( + customer.id, + id || '', + { + page: '1', + }, + ); + + return defer({payout, payoutLogs}); +} + +export default function AccountPayoutsId() { + const data = useLoaderData(); + + return ( + + + + + ); +} + +const PayoutLogs = ({data}: {data: Promise}) => { + return ( + Vent et øjeblik}> + + {({payload}) => { + return ( + + + + Type + Title + Dato + Beløb + + + + {payload.totalCount > 0 ? ( + + {payload.results.map((payout, index) => { + return ( + + {isShipping(payout.referenceDocument) ? ( + <> + Forsendelse + + {payout.referenceDocument.destination.name} + + {payout.createdAt} + + {payout.referenceDocument.cost.value} DKK + + + ) : ( + <> + Behandlinger + + {payout.referenceDocument.title} + + {payout.createdAt} + + {payout.referenceDocument.price} DKK + + + )} + + ); + })} + + ) : ( + + + Der er sket en fejl! + + + )} +
+ ); + }} +
+
+ ); +}; + +const Payout = ({data}: {data: Promise}) => { + return ( + asd}> + + {({payload}) => { + return ( + + + + Total: {payload.amount} {payload.currencyCode} + + Dato: {payload.date.toString()} + Betalingsmetode: {payload.payoutType} + {payload.payoutDetails ? ( + <> + {isMobilePay(payload.payoutDetails) ? ( + <> + + MobilePay: {payload.payoutDetails.phoneNumber} + + + ) : ( + <> + + Bank overførsel: {payload.payoutDetails.bankName} + + + {payload.payoutDetails.regNum} /{' '} + {payload.payoutDetails.accountNum} + + + )} + + ) : null} + + + ); + }} + + + ); +}; diff --git a/app/routes/($locale).account.payouts._index.tsx b/app/routes/($locale).account.payouts._index.tsx index efe325a2..7337c2ae 100644 --- a/app/routes/($locale).account.payouts._index.tsx +++ b/app/routes/($locale).account.payouts._index.tsx @@ -38,19 +38,11 @@ export async function loader({context}: LoaderFunctionArgs) { return defer({payoutAccount, payoutBalance, payouts}); } -const elements = [ - {position: 6, mass: 12.011, symbol: 'C', name: 'Carbon'}, - {position: 7, mass: 14.007, symbol: 'N', name: 'Nitrogen'}, - {position: 39, mass: 88.906, symbol: 'Y', name: 'Yttrium'}, - {position: 56, mass: 137.33, symbol: 'Ba', name: 'Barium'}, - {position: 58, mass: 140.12, symbol: 'Ce', name: 'Cerium'}, -]; - export default function AccountPayoutsIndex() { const data = useLoaderData(); return ( - + @@ -65,13 +57,14 @@ export default function AccountPayoutsIndex() { {({payload}) => { return ( - + Dato Status Beløb + - @@ -86,6 +79,16 @@ export default function AccountPayoutsIndex() { {payout.status}{payout.amount} DKK + + + ))} @@ -121,7 +124,9 @@ const PayoutBalance = ({ Balance - DKK {payload.totalAmount} + Total: {payload.totalAmount} DKK + Kørsel: {payload.totalShippingAmount} DKK + Behandlinger: {payload.totalLineItems} ); From 9db351f3da71f483545ffd02ecc9483ca38746cf Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Mon, 1 Apr 2024 21:59:38 +0200 Subject: [PATCH 5/7] update api --- app/lib/api/model/customerPayoutLog.ts | 2 ++ app/lib/api/model/shippingAllOf.ts | 2 ++ app/lib/zod/bookingShopifyApi.ts | 20 ++++++++++++++++++++ openapi.yaml | 12 ++++++++++++ 4 files changed, 36 insertions(+) diff --git a/app/lib/api/model/customerPayoutLog.ts b/app/lib/api/model/customerPayoutLog.ts index 7fd84b9c..ec8d68aa 100644 --- a/app/lib/api/model/customerPayoutLog.ts +++ b/app/lib/api/model/customerPayoutLog.ts @@ -11,6 +11,8 @@ export interface CustomerPayoutLog { _id: string; createdAt: string; customerId: number; + orderCreatedAt: string; + orderId: number; payout: string; referenceDocument: CustomerPayoutLogReferenceDocument; referenceId: string; diff --git a/app/lib/api/model/shippingAllOf.ts b/app/lib/api/model/shippingAllOf.ts index 2a40e6d7..a8c0aad1 100644 --- a/app/lib/api/model/shippingAllOf.ts +++ b/app/lib/api/model/shippingAllOf.ts @@ -8,6 +8,8 @@ import type {CustomerLocation} from './customerLocation'; export type ShippingAllOf = { _id: string; + created_at: string; location: string; origin: CustomerLocation; + updated_at: string; }; diff --git a/app/lib/zod/bookingShopifyApi.ts b/app/lib/zod/bookingShopifyApi.ts index 186a0c7c..7b2b539c 100644 --- a/app/lib/zod/bookingShopifyApi.ts +++ b/app/lib/zod/bookingShopifyApi.ts @@ -619,6 +619,8 @@ export const customerBookingGetByGroupResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ) .optional(), @@ -1058,6 +1060,8 @@ export const customerBookingRangeResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ) .optional(), @@ -1829,6 +1833,8 @@ export const customerOrderGetResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ) .optional(), @@ -1989,6 +1995,8 @@ export const customerPayoutLogPaginateResponse = zod.object({ zod.object({ _id: zod.string(), customerId: zod.number(), + orderId: zod.number(), + orderCreatedAt: zod.string(), referenceType: zod.enum(['Shipping', 'LineItem']), referenceId: zod.string(), payout: zod.string(), @@ -2096,6 +2104,8 @@ export const customerPayoutLogPaginateResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ), ), @@ -3143,6 +3153,8 @@ export const shippingCreateResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ), }); @@ -3211,6 +3223,8 @@ export const shippingCalculateResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ), }); @@ -3275,6 +3289,8 @@ export const shippingGetResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ), }); @@ -3349,6 +3365,8 @@ export const userAvailabilityGenerateResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ) .optional(), @@ -3450,6 +3468,8 @@ export const userAvailabilityGetResponse = zod.object({ startFee: zod.number(), }), ), + created_at: zod.string(), + updated_at: zod.string(), }), ) .optional(), diff --git a/openapi.yaml b/openapi.yaml index 318b7cee..41c68abe 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1462,6 +1462,10 @@ components: type: string customerId: type: number + orderId: + type: number + orderCreatedAt: + type: string referenceType: $ref: '#/components/schemas/CustomerPayoutLogType' referenceId: @@ -1478,6 +1482,8 @@ components: required: - _id - customerId + - orderId + - orderCreatedAt - referenceType - referenceId - referenceDocument @@ -2610,10 +2616,16 @@ components: type: string origin: $ref: '#/components/schemas/CustomerLocation' + created_at: + type: string + updated_at: + type: string required: - _id - location - origin + - created_at + - updated_at ShippingCostDestination: type: object properties: From 67d560fad9cecedb740941890b0fd5362c2f0b78 Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Mon, 1 Apr 2024 22:01:47 +0200 Subject: [PATCH 6/7] Improve date formatting and update Suspense fallback text in payout logs --- app/routes/($locale).account.payouts.$id.tsx | 15 +++++++++++++-- app/routes/($locale).account.payouts._index.tsx | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/routes/($locale).account.payouts.$id.tsx b/app/routes/($locale).account.payouts.$id.tsx index 6066661a..eaf2d889 100644 --- a/app/routes/($locale).account.payouts.$id.tsx +++ b/app/routes/($locale).account.payouts.$id.tsx @@ -4,6 +4,8 @@ import {getCustomer} from '~/lib/get-customer'; import {Await, useLoaderData} from '@remix-run/react'; +import {format} from 'date-fns'; +import {da} from 'date-fns/locale'; import {Suspense} from 'react'; import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi'; import type { @@ -76,9 +78,14 @@ const PayoutLogs = ({data}: {data: Promise}) => { <> Forsendelse + {payout.referenceDocument.origin.name} -{' '} {payout.referenceDocument.destination.name} - {payout.createdAt} + + {format(new Date(payout.orderCreatedAt), 'PPPP', { + locale: da, + })} + {payout.referenceDocument.cost.value} DKK @@ -89,7 +96,11 @@ const PayoutLogs = ({data}: {data: Promise}) => { {payout.referenceDocument.title} - {payout.createdAt} + + {format(new Date(payout.orderCreatedAt), 'PPPP', { + locale: da, + })} + {payout.referenceDocument.price} DKK diff --git a/app/routes/($locale).account.payouts._index.tsx b/app/routes/($locale).account.payouts._index.tsx index 7337c2ae..be222534 100644 --- a/app/routes/($locale).account.payouts._index.tsx +++ b/app/routes/($locale).account.payouts._index.tsx @@ -53,7 +53,7 @@ export default function AccountPayoutsIndex() { Listen af alle udbetalinger der er foretagt - asd}> + Henter udbetalingshistorik...}> {({payload}) => { return ( From f8e8e3e52f2b57e57af103c27285c60139b9a930 Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Mon, 1 Apr 2024 22:32:30 +0200 Subject: [PATCH 7/7] Add payout details and request functionality to account payouts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Implement AccountTitle and AccountContent components for better layout structure in payout pages • Add payout request form and action to create payout requests • Introduce Skeleton component for loading states in payout account and balance components • Reorganize payout logs table, adding order view and adjusting column order • Include new payout request route and action to handle payout creation --- app/routes/($locale).account.payouts.$id.tsx | 35 ++-- .../($locale).account.payouts._index.tsx | 156 ++++++++++-------- .../($locale).account.payouts.create.tsx | 152 ++++++++++------- .../($locale).account.payouts.request.ts | 11 ++ app/routes/($locale).account.payouts.tsx | 19 +-- 5 files changed, 205 insertions(+), 168 deletions(-) create mode 100644 app/routes/($locale).account.payouts.request.ts diff --git a/app/routes/($locale).account.payouts.$id.tsx b/app/routes/($locale).account.payouts.$id.tsx index eaf2d889..9c58829f 100644 --- a/app/routes/($locale).account.payouts.$id.tsx +++ b/app/routes/($locale).account.payouts.$id.tsx @@ -7,6 +7,8 @@ import {Await, useLoaderData} from '@remix-run/react'; import {format} from 'date-fns'; import {da} from 'date-fns/locale'; import {Suspense} from 'react'; +import {AccountContent} from '~/components/account/AccountContent'; +import {AccountTitle} from '~/components/account/AccountTitle'; import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi'; import type { CustomerPayoutGetResponse, @@ -46,10 +48,16 @@ export default function AccountPayoutsId() { const data = useLoaderData(); return ( - - - - + <> + + + + + + + + + ); } @@ -62,10 +70,11 @@ const PayoutLogs = ({data}: {data: Promise}) => {
+ # Type Title - Dato Beløb + Dato @@ -74,6 +83,7 @@ const PayoutLogs = ({data}: {data: Promise}) => { {payload.results.map((payout, index) => { return ( + Vis order {isShipping(payout.referenceDocument) ? ( <> Forsendelse @@ -81,11 +91,6 @@ const PayoutLogs = ({data}: {data: Promise}) => { {payout.referenceDocument.origin.name} -{' '} {payout.referenceDocument.destination.name} - - {format(new Date(payout.orderCreatedAt), 'PPPP', { - locale: da, - })} - {payout.referenceDocument.cost.value} DKK @@ -96,16 +101,16 @@ const PayoutLogs = ({data}: {data: Promise}) => { {payout.referenceDocument.title} - - {format(new Date(payout.orderCreatedAt), 'PPPP', { - locale: da, - })} - {payout.referenceDocument.price} DKK )} + + {format(new Date(payout.orderCreatedAt), 'PPPP', { + locale: da, + })} + ); })} diff --git a/app/routes/($locale).account.payouts._index.tsx b/app/routes/($locale).account.payouts._index.tsx index be222534..0c0af20f 100644 --- a/app/routes/($locale).account.payouts._index.tsx +++ b/app/routes/($locale).account.payouts._index.tsx @@ -3,6 +3,7 @@ import { Button, Card, SimpleGrid, + Skeleton, Stack, Table, Text, @@ -13,6 +14,8 @@ import {defer, type LoaderFunctionArgs} from '@shopify/remix-oxygen'; import {format} from 'date-fns'; import {da} from 'date-fns/locale'; import {Suspense} from 'react'; +import {AccountContent} from '~/components/account/AccountContent'; +import {AccountTitle} from '~/components/account/AccountTitle'; import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi'; import type { CustomerPayoutAccountGetResponse, @@ -42,72 +45,78 @@ export default function AccountPayoutsIndex() { const data = useLoaderData(); return ( - - - - - + <> + -
- Historik - Listen af alle udbetalinger der er foretagt -
+ + + + + + - Henter udbetalingshistorik...}> - - {({payload}) => { - return ( - -
- - - Dato - Status - Beløb - - - - +
+ Historik + Listen af alle udbetalinger der er foretagt +
- {payload.totalCount > 0 ? ( - - {payload.results.map((payout) => ( - - - {format(new Date(), 'yyyy-MM-dd', {locale: da})} - - - {payout.status} - - {payout.amount} DKK - - - + Henter udbetalingshistorik...}> + + {({payload}) => { + return ( + +
+ + + Dato + Status + Beløb + - ))} - - ) : ( - - - - Der er ikke oprettet udbetalinger endnu! - - - - )} -
-
- ); - }} -
-
- + + + {payload.totalCount > 0 ? ( + + {payload.results.map((payout) => ( + + + {format(new Date(), 'yyyy-MM-dd', {locale: da})} + + + {payout.status} + + {payout.amount} DKK + + + + + ))} + + ) : ( + + + + Der er ikke oprettet udbetalinger endnu! + + + + )} + + + ); + }} + +
+ + + ); } @@ -117,17 +126,22 @@ const PayoutBalance = ({ payoutBalance: Promise; }) => { return ( - asd}> + }> {({payload}) => { return ( - - - Balance - Total: {payload.totalAmount} DKK - Kørsel: {payload.totalShippingAmount} DKK - Behandlinger: {payload.totalLineItems} - + + Balance + Total: {payload.totalAmount} DKK + Kørsel: {payload.totalShippingAmount} DKK + Behandlinger: {payload.totalLineItems} + {payload.totalAmount > 0 ? ( +
+ +
+ ) : null}
); }} @@ -142,7 +156,7 @@ const PayoutAccount = ({ payoutAccount: Promise; }) => { return ( - asd}> + }> {({payload}) => { return ( diff --git a/app/routes/($locale).account.payouts.create.tsx b/app/routes/($locale).account.payouts.create.tsx index 18474c32..98d0789f 100644 --- a/app/routes/($locale).account.payouts.create.tsx +++ b/app/routes/($locale).account.payouts.create.tsx @@ -21,6 +21,8 @@ import { } from '@conform-to/react'; import {Form, useActionData} from '@remix-run/react'; +import {AccountContent} from '~/components/account/AccountContent'; +import {AccountTitle} from '~/components/account/AccountTitle'; import {SubmitButton} from '~/components/form/SubmitButton'; import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi'; import {CustomerPayoutAccountType} from '~/lib/api/model'; @@ -94,75 +96,97 @@ export default function AccountPayoutsSettings() { const payoutType = useInputControl(fields.payoutType); return ( -
- -
- Bank konto - - Vi skal bruge din regnr og kontonummer for at sende dig din - udbetalinger. - -
+ <> + - - {getCollectionProps(fields.payoutType, { - type: 'radio', - options: [ - CustomerPayoutAccountType.BANK_ACCOUNT, - CustomerPayoutAccountType.MOBILE_PAY, - ], - }).map((props) => ( - - ))} - + + + +
+ Bank konto + + Vi skal bruge din regnr og kontonummer for at sende dig din + udbetalinger. + +
- {payoutType.value === CustomerPayoutAccountType.BANK_ACCOUNT ? ( - <> - - - + + {getCollectionProps(fields.payoutType, { + type: 'radio', + options: [ + CustomerPayoutAccountType.BANK_ACCOUNT, + CustomerPayoutAccountType.MOBILE_PAY, + ], + }).map((props) => ( + + ))} + + + {payoutType.value === CustomerPayoutAccountType.BANK_ACCOUNT ? ( + <> + + + + + + + ) : ( - - - ) : ( - - )} + )} - Gem -
- + Gem +
+ + + ); } diff --git a/app/routes/($locale).account.payouts.request.ts b/app/routes/($locale).account.payouts.request.ts new file mode 100644 index 00000000..d64c2f8d --- /dev/null +++ b/app/routes/($locale).account.payouts.request.ts @@ -0,0 +1,11 @@ +import {redirect, type ActionFunction} from '@shopify/remix-oxygen'; +import {getBookingShopifyApi} from '~/lib/api/bookingShopifyApi'; +import {getCustomer} from '~/lib/get-customer'; + +export const action: ActionFunction = async ({context, params}) => { + const customer = await getCustomer({context}); + + await getBookingShopifyApi().customerPayoutCreate(customer.id); + + return redirect(`/account/payouts`); +}; diff --git a/app/routes/($locale).account.payouts.tsx b/app/routes/($locale).account.payouts.tsx index 9d976b5a..a8cfa971 100644 --- a/app/routes/($locale).account.payouts.tsx +++ b/app/routes/($locale).account.payouts.tsx @@ -1,14 +1,10 @@ import {Outlet} from '@remix-run/react'; -import {json, type LoaderFunctionArgs} from '@shopify/remix-oxygen'; -import {AccountContent} from '~/components/account/AccountContent'; -import {AccountTitle} from '~/components/account/AccountTitle'; import type { CustomerPayoutAccountPayoutDetails, CustomerPayoutBankAccount, CustomerPayoutMobilePay, } from '~/lib/api/model'; -import {getCustomer} from '~/lib/get-customer'; export function isMobilePay( details: CustomerPayoutAccountPayoutDetails, @@ -22,19 +18,6 @@ export function isBankAccount( return (details as CustomerPayoutBankAccount).bankName !== undefined; } -export async function loader({context}: LoaderFunctionArgs) { - const customer = await getCustomer({context}); - return json({}); -} - export default function AccountPayouts() { - return ( - <> - - - - - - - ); + return ; }