diff --git a/app/api/gql/gql.ts b/app/api/gql/gql.ts index eb4693d..243aea0 100644 --- a/app/api/gql/gql.ts +++ b/app/api/gql/gql.ts @@ -13,10 +13,10 @@ import type { TypedDocumentNode as DocumentNode } from "@graphql-typed-document- * Therefore it is highly recommended to use the babel or swc plugin for production. */ const documents = { - "query FetchExampleEvents {\n events {\n id\n description\n community {\n id\n name\n }\n tags {\n id\n name\n description\n }\n }\n}": - types.FetchExampleEventsDocument, "query myTickets($input: PaginatedInputMyTicketsSearchValues!) {\n myTickets(input: $input) {\n data {\n approvalStatus\n id\n paymentStatus\n redemptionStatus\n }\n pagination {\n currentPage\n pageSize\n totalPages\n totalRecords\n }\n }\n}": types.MyTicketsDocument, + "mutation CheckPurchaseOrderStatus($input: CheckForPurchaseOrderInput!) {\n checkPurchaseOrderStatus(input: $input) {\n status\n tickets {\n approvalStatus\n paymentStatus\n redemptionStatus\n }\n }\n}": + types.CheckPurchaseOrderStatusDocument, "mutation createPurchaseOrder($input: TicketClaimInput!) {\n claimUserTicket(input: $input) {\n __typename\n ... on PurchaseOrder {\n __typename\n id\n currency {\n id\n }\n finalPrice\n paymentLink\n status\n tickets {\n id\n approvalStatus\n redemptionStatus\n paymentStatus\n }\n }\n ... on RedeemUserTicketError {\n __typename\n error\n errorMessage\n }\n }\n}": types.CreatePurchaseOrderDocument, "fragment EventTicketFragment on Ticket {\n id\n name\n description\n quantity\n isFree\n startDateTime\n status\n isUnlimited\n prices {\n id\n amount\n currency {\n currency\n id\n }\n }\n}": @@ -43,14 +43,14 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: "query FetchExampleEvents {\n events {\n id\n description\n community {\n id\n name\n }\n tags {\n id\n name\n description\n }\n }\n}", -): (typeof documents)["query FetchExampleEvents {\n events {\n id\n description\n community {\n id\n name\n }\n tags {\n id\n name\n description\n }\n }\n}"]; + source: "query myTickets($input: PaginatedInputMyTicketsSearchValues!) {\n myTickets(input: $input) {\n data {\n approvalStatus\n id\n paymentStatus\n redemptionStatus\n }\n pagination {\n currentPage\n pageSize\n totalPages\n totalRecords\n }\n }\n}", +): (typeof documents)["query myTickets($input: PaginatedInputMyTicketsSearchValues!) {\n myTickets(input: $input) {\n data {\n approvalStatus\n id\n paymentStatus\n redemptionStatus\n }\n pagination {\n currentPage\n pageSize\n totalPages\n totalRecords\n }\n }\n}"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: "query myTickets($input: PaginatedInputMyTicketsSearchValues!) {\n myTickets(input: $input) {\n data {\n approvalStatus\n id\n paymentStatus\n redemptionStatus\n }\n pagination {\n currentPage\n pageSize\n totalPages\n totalRecords\n }\n }\n}", -): (typeof documents)["query myTickets($input: PaginatedInputMyTicketsSearchValues!) {\n myTickets(input: $input) {\n data {\n approvalStatus\n id\n paymentStatus\n redemptionStatus\n }\n pagination {\n currentPage\n pageSize\n totalPages\n totalRecords\n }\n }\n}"]; + source: "mutation CheckPurchaseOrderStatus($input: CheckForPurchaseOrderInput!) {\n checkPurchaseOrderStatus(input: $input) {\n status\n tickets {\n approvalStatus\n paymentStatus\n redemptionStatus\n }\n }\n}", +): (typeof documents)["mutation CheckPurchaseOrderStatus($input: CheckForPurchaseOrderInput!) {\n checkPurchaseOrderStatus(input: $input) {\n status\n tickets {\n approvalStatus\n paymentStatus\n redemptionStatus\n }\n }\n}"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/app/api/gql/graphql.ts b/app/api/gql/graphql.ts index bf2978d..7471031 100644 --- a/app/api/gql/graphql.ts +++ b/app/api/gql/graphql.ts @@ -218,6 +218,7 @@ export type EventsSearchInput = { startDateTimeFrom: InputMaybe; startDateTimeTo: InputMaybe; status: InputMaybe; + userHasTickets: InputMaybe; visibility: InputMaybe; }; @@ -382,6 +383,17 @@ export type MyTicketsSearchValues = { redemptionStatus: InputMaybe; }; +/** Type used for querying the paginated leaves and it's paginated meta data */ +export type PaginatedEvent = { + data: Array; + pagination: Pagination; +}; + +export type PaginatedInputEventsSearchInput = { + pagination: PaginationSearchInputParams; + search: InputMaybe; +}; + export type PaginatedInputMyTicketsSearchValues = { pagination: PaginationSearchInputParams; search: InputMaybe; @@ -469,8 +481,6 @@ export type Query = { event: Maybe; /** Get a list of images, that are attached to an event */ eventImages: Array; - /** Get a list of events. Filter by name, id, status or date */ - events: Array; /** Get the current user */ me: User; /** Get a list of tickets for the current user */ @@ -479,6 +489,8 @@ export type Query = { salaries: Array; /** Search a consolidated payment logs, by date, aggregated by platform and currency_id */ searchConsolidatedPaymentLogs: Array; + /** Get a list of events. Filter by name, id, status or date */ + searchEvents: PaginatedEvent; /** Search on the payment logs by date, and returns a list of payment logs */ searchPaymentLogs: Array; status: Scalars["String"]["output"]; @@ -524,10 +536,6 @@ export type QueryEventImagesArgs = { input: EventImageSearch; }; -export type QueryEventsArgs = { - input: InputMaybe; -}; - export type QueryMyTicketsArgs = { input: PaginatedInputMyTicketsSearchValues; }; @@ -536,6 +544,10 @@ export type QuerySearchConsolidatedPaymentLogsArgs = { input: SearchPaymentLogsInput; }; +export type QuerySearchEventsArgs = { + input: PaginatedInputEventsSearchInput; +}; + export type QuerySearchPaymentLogsArgs = { input: SearchPaymentLogsInput; }; @@ -761,7 +773,9 @@ export type UpdateSalaryInput = { export type User = { bio: Maybe; communities: Array; + email: Maybe; id: Scalars["String"]["output"]; + imageUrl: Maybe; isSuperAdmin: Maybe; lastName: Maybe; name: Maybe; @@ -842,21 +856,6 @@ export type UserSearchInput = { tags: InputMaybe>; }; -export type FetchExampleEventsQueryVariables = Exact<{ [key: string]: never }>; - -export type FetchExampleEventsQuery = { - events: Array<{ - id: string; - description: string | null; - community: { id: string; name: string | null } | null; - tags: Array<{ - id: string; - name: string | null; - description: string | null; - }>; - }>; -}; - export type MyTicketsQueryVariables = Exact<{ input: PaginatedInputMyTicketsSearchValues; }>; @@ -878,6 +877,21 @@ export type MyTicketsQuery = { }; }; +export type CheckPurchaseOrderStatusMutationVariables = Exact<{ + input: CheckForPurchaseOrderInput; +}>; + +export type CheckPurchaseOrderStatusMutation = { + checkPurchaseOrderStatus: { + status: PurchaseOrderStatusEnum | null; + tickets: Array<{ + approvalStatus: TicketApprovalStatus; + paymentStatus: TicketPaymentStatus; + redemptionStatus: TicketRedemptionStatus; + }>; + }; +}; + export type CreatePurchaseOrderMutationVariables = Exact<{ input: TicketClaimInput; }>; @@ -996,46 +1010,94 @@ export const EventTicketFragmentFragmentDoc = { }, ], } as unknown as DocumentNode; -export const FetchExampleEventsDocument = { +export const MyTicketsDocument = { kind: "Document", definitions: [ { kind: "OperationDefinition", operation: "query", - name: { kind: "Name", value: "FetchExampleEvents" }, + name: { kind: "Name", value: "myTickets" }, + variableDefinitions: [ + { + kind: "VariableDefinition", + variable: { + kind: "Variable", + name: { kind: "Name", value: "input" }, + }, + type: { + kind: "NonNullType", + type: { + kind: "NamedType", + name: { + kind: "Name", + value: "PaginatedInputMyTicketsSearchValues", + }, + }, + }, + }, + ], selectionSet: { kind: "SelectionSet", selections: [ { kind: "Field", - name: { kind: "Name", value: "events" }, + name: { kind: "Name", value: "myTickets" }, + arguments: [ + { + kind: "Argument", + name: { kind: "Name", value: "input" }, + value: { + kind: "Variable", + name: { kind: "Name", value: "input" }, + }, + }, + ], selectionSet: { kind: "SelectionSet", selections: [ - { kind: "Field", name: { kind: "Name", value: "id" } }, - { kind: "Field", name: { kind: "Name", value: "description" } }, { kind: "Field", - name: { kind: "Name", value: "community" }, + name: { kind: "Name", value: "data" }, selectionSet: { kind: "SelectionSet", selections: [ + { + kind: "Field", + name: { kind: "Name", value: "approvalStatus" }, + }, { kind: "Field", name: { kind: "Name", value: "id" } }, - { kind: "Field", name: { kind: "Name", value: "name" } }, + { + kind: "Field", + name: { kind: "Name", value: "paymentStatus" }, + }, + { + kind: "Field", + name: { kind: "Name", value: "redemptionStatus" }, + }, ], }, }, { kind: "Field", - name: { kind: "Name", value: "tags" }, + name: { kind: "Name", value: "pagination" }, selectionSet: { kind: "SelectionSet", selections: [ - { kind: "Field", name: { kind: "Name", value: "id" } }, - { kind: "Field", name: { kind: "Name", value: "name" } }, { kind: "Field", - name: { kind: "Name", value: "description" }, + name: { kind: "Name", value: "currentPage" }, + }, + { + kind: "Field", + name: { kind: "Name", value: "pageSize" }, + }, + { + kind: "Field", + name: { kind: "Name", value: "totalPages" }, + }, + { + kind: "Field", + name: { kind: "Name", value: "totalRecords" }, }, ], }, @@ -1047,17 +1109,14 @@ export const FetchExampleEventsDocument = { }, }, ], -} as unknown as DocumentNode< - FetchExampleEventsQuery, - FetchExampleEventsQueryVariables ->; -export const MyTicketsDocument = { +} as unknown as DocumentNode; +export const CheckPurchaseOrderStatusDocument = { kind: "Document", definitions: [ { kind: "OperationDefinition", - operation: "query", - name: { kind: "Name", value: "myTickets" }, + operation: "mutation", + name: { kind: "Name", value: "CheckPurchaseOrderStatus" }, variableDefinitions: [ { kind: "VariableDefinition", @@ -1069,10 +1128,7 @@ export const MyTicketsDocument = { kind: "NonNullType", type: { kind: "NamedType", - name: { - kind: "Name", - value: "PaginatedInputMyTicketsSearchValues", - }, + name: { kind: "Name", value: "CheckForPurchaseOrderInput" }, }, }, }, @@ -1082,7 +1138,7 @@ export const MyTicketsDocument = { selections: [ { kind: "Field", - name: { kind: "Name", value: "myTickets" }, + name: { kind: "Name", value: "checkPurchaseOrderStatus" }, arguments: [ { kind: "Argument", @@ -1096,9 +1152,10 @@ export const MyTicketsDocument = { selectionSet: { kind: "SelectionSet", selections: [ + { kind: "Field", name: { kind: "Name", value: "status" } }, { kind: "Field", - name: { kind: "Name", value: "data" }, + name: { kind: "Name", value: "tickets" }, selectionSet: { kind: "SelectionSet", selections: [ @@ -1106,7 +1163,6 @@ export const MyTicketsDocument = { kind: "Field", name: { kind: "Name", value: "approvalStatus" }, }, - { kind: "Field", name: { kind: "Name", value: "id" } }, { kind: "Field", name: { kind: "Name", value: "paymentStatus" }, @@ -1118,31 +1174,6 @@ export const MyTicketsDocument = { ], }, }, - { - kind: "Field", - name: { kind: "Name", value: "pagination" }, - selectionSet: { - kind: "SelectionSet", - selections: [ - { - kind: "Field", - name: { kind: "Name", value: "currentPage" }, - }, - { - kind: "Field", - name: { kind: "Name", value: "pageSize" }, - }, - { - kind: "Field", - name: { kind: "Name", value: "totalPages" }, - }, - { - kind: "Field", - name: { kind: "Name", value: "totalRecords" }, - }, - ], - }, - }, ], }, }, @@ -1150,7 +1181,10 @@ export const MyTicketsDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + CheckPurchaseOrderStatusMutation, + CheckPurchaseOrderStatusMutationVariables +>; export const CreatePurchaseOrderDocument = { kind: "Document", definitions: [ diff --git a/app/api/gql/schema.gql b/app/api/gql/schema.gql index 1fa0c52..e1adaf3 100644 --- a/app/api/gql/schema.gql +++ b/app/api/gql/schema.gql @@ -208,6 +208,7 @@ input EventsSearchInput { startDateTimeFrom: DateTime startDateTimeTo: DateTime status: EventStatus + userHasTickets: Boolean visibility: EventVisibility } @@ -350,6 +351,19 @@ input MyTicketsSearchValues { redemptionStatus: TicketRedemptionStatus } +""" +Type used for querying the paginated leaves and it's paginated meta data +""" +type PaginatedEvent { + data: [Event!]! + pagination: Pagination! +} + +input PaginatedInputEventsSearchInput { + pagination: PaginationSearchInputParams! = { page: 0, pageSize: 20 } + search: EventsSearchInput +} + input PaginatedInputMyTicketsSearchValues { pagination: PaginationSearchInputParams! = { page: 0, pageSize: 20 } search: MyTicketsSearchValues @@ -470,11 +484,6 @@ type Query { """ eventImages(input: EventImageSearch!): [SanityAssetRef!]! - """ - Get a list of events. Filter by name, id, status or date - """ - events(input: EventsSearchInput): [Event!]! - """ Get the current user """ @@ -497,6 +506,11 @@ type Query { input: SearchPaymentLogsInput! ): [ConsolidatedPaymentLogEntry!]! + """ + Get a list of events. Filter by name, id, status or date + """ + searchEvents(input: PaginatedInputEventsSearchInput!): PaginatedEvent! + """ Search on the payment logs by date, and returns a list of payment logs """ @@ -773,7 +787,9 @@ Representation of a user type User { bio: String communities: [Community!]! + email: String id: String! + imageUrl: String isSuperAdmin: Boolean lastName: String name: String diff --git a/app/components/LandingPageEvents/graphql/FetchExampleEvents.generated.tsx b/app/components/LandingPageEvents/graphql/FetchExampleEvents.generated.tsx deleted file mode 100644 index a8113cb..0000000 --- a/app/components/LandingPageEvents/graphql/FetchExampleEvents.generated.tsx +++ /dev/null @@ -1,116 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ -// @ts-nocheck -/* eslint-disable */ -/* prettier-ignore */ -/* This file is automatically generated. Please do not modify it manually. */ -import * as Types from '../../../api/gql/graphql'; - -import { gql } from "graphql-tag"; -import * as Apollo from "@apollo/client"; -const defaultOptions = {} as const; -export type FetchExampleEventsQueryVariables = Types.Exact<{ - [key: string]: never; -}>; - -export type FetchExampleEventsQuery = { - __typename?: "Query"; - events: Array<{ - __typename?: "Event"; - id: string; - description?: string | null; - community?: { - __typename?: "Community"; - id: string; - name?: string | null; - } | null; - tags: Array<{ - __typename?: "Tag"; - id: string; - name?: string | null; - description?: string | null; - }>; - }>; -}; - -export const FetchExampleEventsDocument = gql` - query FetchExampleEvents { - events { - id - description - community { - id - name - } - tags { - id - name - description - } - } - } -`; - -/** - * __useFetchExampleEventsQuery__ - * - * To run a query within a React component, call `useFetchExampleEventsQuery` and pass it any options that fit your needs. - * When your component renders, `useFetchExampleEventsQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useFetchExampleEventsQuery({ - * variables: { - * }, - * }); - */ -export function useFetchExampleEventsQuery( - baseOptions?: Apollo.QueryHookOptions< - FetchExampleEventsQuery, - FetchExampleEventsQueryVariables - >, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useQuery< - FetchExampleEventsQuery, - FetchExampleEventsQueryVariables - >(FetchExampleEventsDocument, options); -} -export function useFetchExampleEventsLazyQuery( - baseOptions?: Apollo.LazyQueryHookOptions< - FetchExampleEventsQuery, - FetchExampleEventsQueryVariables - >, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useLazyQuery< - FetchExampleEventsQuery, - FetchExampleEventsQueryVariables - >(FetchExampleEventsDocument, options); -} -export function useFetchExampleEventsSuspenseQuery( - baseOptions?: Apollo.SuspenseQueryHookOptions< - FetchExampleEventsQuery, - FetchExampleEventsQueryVariables - >, -) { - const options = { ...defaultOptions, ...baseOptions }; - return Apollo.useSuspenseQuery< - FetchExampleEventsQuery, - FetchExampleEventsQueryVariables - >(FetchExampleEventsDocument, options); -} -export type FetchExampleEventsQueryHookResult = ReturnType< - typeof useFetchExampleEventsQuery ->; -export type FetchExampleEventsLazyQueryHookResult = ReturnType< - typeof useFetchExampleEventsLazyQuery ->; -export type FetchExampleEventsSuspenseQueryHookResult = ReturnType< - typeof useFetchExampleEventsSuspenseQuery ->; -export type FetchExampleEventsQueryResult = Apollo.QueryResult< - FetchExampleEventsQuery, - FetchExampleEventsQueryVariables ->; diff --git a/app/components/LandingPageEvents/graphql/FetchExampleEvents.gql b/app/components/LandingPageEvents/graphql/FetchExampleEvents.gql deleted file mode 100644 index c2be70e..0000000 --- a/app/components/LandingPageEvents/graphql/FetchExampleEvents.gql +++ /dev/null @@ -1,15 +0,0 @@ -query FetchExampleEvents { - events { - id - description - community { - id - name - } - tags { - id - name - description - } - } -} diff --git a/app/components/LandingPageEvents/index.tsx b/app/components/LandingPageEvents/index.tsx deleted file mode 100644 index 7b7eaf9..0000000 --- a/app/components/LandingPageEvents/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { useFetchExampleEventsQuery } from "./graphql/FetchExampleEvents.generated"; - -export const LandingPageEvents = () => { - const events = useFetchExampleEventsQuery(); - - return ( - <> - {events.data?.events.map((event) =>
{event.id}
)} - - ); -}; diff --git a/app/components/PurchaseOrder/Callback.tsx b/app/components/PurchaseOrder/Callback.tsx new file mode 100644 index 0000000..8b319e9 --- /dev/null +++ b/app/components/PurchaseOrder/Callback.tsx @@ -0,0 +1,66 @@ +import { useCallback, useEffect, useRef } from "react"; +import { toast } from "sonner"; + +import { PurchaseOrderStatusEnum } from "~/api/gql/graphql"; +import { urls } from "~/utils/urls"; + +import { useCheckPurchaseOrderStatusMutation } from "./checkPurchaseOrderStatus.generated"; + +type PurchaseCallbackProps = { + purchaseOrderId: string; +}; + +export const PurchaseCallback = ({ + purchaseOrderId, +}: PurchaseCallbackProps) => { + const triggered = useRef(false); + + const [checkPurchaseOrderMutation, { loading, error, data }] = + useCheckPurchaseOrderStatusMutation({ + variables: { + input: { + purchaseOrderId, + }, + }, + }); + + const checkPurchaseOrder = useCallback(checkPurchaseOrderMutation, [ + checkPurchaseOrderMutation, + ]); + + useEffect(() => { + if (!triggered.current) { + void checkPurchaseOrder(); + } + + triggered.current = true; + }, [checkPurchaseOrder]); + + if (loading) { + return
Retrieving order payment status...
; + } + + if (error) { + return toast("Error fetching order status"); + } + + if (!data) { + return <>; + } + + const { status } = data.checkPurchaseOrderStatus; + + if ( + status === PurchaseOrderStatusEnum.Paid || + status === PurchaseOrderStatusEnum.NotRequired + ) { + return ( +
+ Congrats! Go get your{" "} + tickets +
+ ); + } + + return
Ticket not paid
; +}; diff --git a/app/components/PurchaseOrder/checkPurchaseOrderStatus.gql b/app/components/PurchaseOrder/checkPurchaseOrderStatus.gql new file mode 100644 index 0000000..9f7fb59 --- /dev/null +++ b/app/components/PurchaseOrder/checkPurchaseOrderStatus.gql @@ -0,0 +1,10 @@ +mutation CheckPurchaseOrderStatus($input: CheckForPurchaseOrderInput!) { + checkPurchaseOrderStatus(input: $input) { + status + tickets { + approvalStatus + paymentStatus + redemptionStatus + } + } +} diff --git a/app/routes/_authenticated/ordenes/callback/index.tsx b/app/routes/_authenticated/ordenes/callback/index.tsx new file mode 100644 index 0000000..94156c3 --- /dev/null +++ b/app/routes/_authenticated/ordenes/callback/index.tsx @@ -0,0 +1,15 @@ +import { useSearchParams } from "@remix-run/react"; +import { toast } from "sonner"; + +import { PurchaseCallback } from "~/components/PurchaseOrder/Callback"; + +export default function Index() { + const [params] = useSearchParams(); + const purchaseOrderId = params.get("purchaseOrderId"); + + if (!purchaseOrderId) { + return toast("Error fetching purchase order"); + } + + return ; +} diff --git a/app/utils/urls.ts b/app/utils/urls.ts index f426b93..4dab974 100644 --- a/app/utils/urls.ts +++ b/app/utils/urls.ts @@ -5,6 +5,11 @@ export const urls = { evento: (id: string) => `/eventos/${id}`, tickets: (id: string) => `/eventos/${id}/tickets`, }, + ordenes: { + root: "/ordenes", + orden: (id: string) => `/ordenes/${id}`, + tickets: (id: string) => `/ordenes/${id}/tickets`, + }, comunidades: "/comunidades", tickets: { root: "/tickets",