diff --git a/app/composables/graphql/generated.ts b/app/composables/graphql/generated.ts index f1a9ca2..849c262 100644 --- a/app/composables/graphql/generated.ts +++ b/app/composables/graphql/generated.ts @@ -74,6 +74,28 @@ export type ConnectMessengerInput = { type: MessengerType; }; +export type CounterpartyProfile = { + __typename?: 'CounterpartyProfile'; + bankName: Scalars['String']['output']; + bik: Scalars['String']['output']; + checkingAccount: Scalars['String']['output']; + companyFullName: Scalars['String']['output']; + companyName: Scalars['String']['output']; + correspondentAccount: Scalars['String']['output']; + createdAt: Scalars['DateTime']['output']; + id: Scalars['ID']['output']; + inn: Scalars['String']['output']; + isComplete: Scalars['Boolean']['output']; + kpp?: Maybe; + legalAddress: Scalars['String']['output']; + ogrn?: Maybe; + signerBasis: Scalars['String']['output']; + signerFullName: Scalars['String']['output']; + signerPosition: Scalars['String']['output']; + updatedAt: Scalars['DateTime']['output']; + userId: Scalars['ID']['output']; +}; + export type CreateInvitationInput = { companyName: Scalars['String']['input']; email: Scalars['String']['input']; @@ -153,6 +175,7 @@ export type Mutation = { startOrderWork: Order; submitCalculationOrder: Order; submitReadyOrder: Order; + upsertMyCounterpartyProfile: CounterpartyProfile; verifyLoginCode: AuthSession; }; @@ -261,6 +284,11 @@ export type MutationSubmitReadyOrderArgs = { }; +export type MutationUpsertMyCounterpartyProfileArgs = { + input: UpsertMyCounterpartyProfileInput; +}; + + export type MutationVerifyLoginCodeArgs = { input: VerifyLoginCodeInput; }; @@ -354,6 +382,7 @@ export type Query = { managerNotificationHistory: Array; managerOrders: Array; me?: Maybe; + myCounterpartyProfile?: Maybe; myCurrentOrders: Array; myMessengerConnections: Array; myNotificationHistory: Array; @@ -484,6 +513,22 @@ export type SubmitReadyOrderInput = { items: Array; }; +export type UpsertMyCounterpartyProfileInput = { + bankName: Scalars['String']['input']; + bik: Scalars['String']['input']; + checkingAccount: Scalars['String']['input']; + companyFullName: Scalars['String']['input']; + companyName: Scalars['String']['input']; + correspondentAccount: Scalars['String']['input']; + inn: Scalars['String']['input']; + kpp?: InputMaybe; + legalAddress: Scalars['String']['input']; + ogrn?: InputMaybe; + signerBasis: Scalars['String']['input']; + signerFullName: Scalars['String']['input']; + signerPosition: Scalars['String']['input']; +}; + export type User = { __typename?: 'User'; company?: Maybe; @@ -615,6 +660,18 @@ export type ConnectMessengerMutationVariables = Exact<{ export type ConnectMessengerMutation = { __typename?: 'Mutation', connectMessenger: { __typename?: 'MessengerConnection', id: string, type: MessengerType, channelId: string, isActive: boolean } }; +export type MyCounterpartyProfileQueryVariables = Exact<{ [key: string]: never; }>; + + +export type MyCounterpartyProfileQuery = { __typename?: 'Query', myCounterpartyProfile?: { __typename?: 'CounterpartyProfile', id: string, companyName: string, companyFullName: string, inn: string, kpp?: string | null, ogrn?: string | null, legalAddress: string, bankName: string, bik: string, correspondentAccount: string, checkingAccount: string, signerFullName: string, signerPosition: string, signerBasis: string, isComplete: boolean, updatedAt: any } | null }; + +export type UpsertMyCounterpartyProfileMutationVariables = Exact<{ + input: UpsertMyCounterpartyProfileInput; +}>; + + +export type UpsertMyCounterpartyProfileMutation = { __typename?: 'Mutation', upsertMyCounterpartyProfile: { __typename?: 'CounterpartyProfile', id: string, companyName: string, companyFullName: string, inn: string, kpp?: string | null, ogrn?: string | null, legalAddress: string, bankName: string, bik: string, correspondentAccount: string, checkingAccount: string, signerFullName: string, signerPosition: string, signerBasis: string, isComplete: boolean, updatedAt: any } }; + export const ConsumeLoginTokenDocument = gql` mutation ConsumeLoginToken($token: String!) { @@ -1130,4 +1187,90 @@ export const ConnectMessengerDocument = gql` export function useConnectMessengerMutation(options: VueApolloComposable.UseMutationOptions | ReactiveFunction> = {}) { return VueApolloComposable.useMutation(ConnectMessengerDocument, options); } -export type ConnectMessengerMutationCompositionFunctionResult = VueApolloComposable.UseMutationReturn; \ No newline at end of file +export type ConnectMessengerMutationCompositionFunctionResult = VueApolloComposable.UseMutationReturn; +export const MyCounterpartyProfileDocument = gql` + query MyCounterpartyProfile { + myCounterpartyProfile { + id + companyName + companyFullName + inn + kpp + ogrn + legalAddress + bankName + bik + correspondentAccount + checkingAccount + signerFullName + signerPosition + signerBasis + isComplete + updatedAt + } +} + `; + +/** + * __useMyCounterpartyProfileQuery__ + * + * To run a query within a Vue component, call `useMyCounterpartyProfileQuery` and pass it any options that fit your needs. + * When your component renders, `useMyCounterpartyProfileQuery` returns an object from Apollo Client that contains result, loading and error properties + * you can use to render your UI. + * + * @param options that will be passed into the query, supported options are listed on: https://v4.apollo.vuejs.org/guide-composable/query.html#options; + * + * @example + * const { result, loading, error } = useMyCounterpartyProfileQuery(); + */ +export function useMyCounterpartyProfileQuery(options: VueApolloComposable.UseQueryOptions | VueCompositionApi.Ref> | ReactiveFunction> = {}) { + return VueApolloComposable.useQuery(MyCounterpartyProfileDocument, {}, options); +} +export function useMyCounterpartyProfileLazyQuery(options: VueApolloComposable.UseQueryOptions | VueCompositionApi.Ref> | ReactiveFunction> = {}) { + return VueApolloComposable.useLazyQuery(MyCounterpartyProfileDocument, {}, options); +} +export type MyCounterpartyProfileQueryCompositionFunctionResult = VueApolloComposable.UseQueryReturn; +export const UpsertMyCounterpartyProfileDocument = gql` + mutation UpsertMyCounterpartyProfile($input: UpsertMyCounterpartyProfileInput!) { + upsertMyCounterpartyProfile(input: $input) { + id + companyName + companyFullName + inn + kpp + ogrn + legalAddress + bankName + bik + correspondentAccount + checkingAccount + signerFullName + signerPosition + signerBasis + isComplete + updatedAt + } +} + `; + +/** + * __useUpsertMyCounterpartyProfileMutation__ + * + * To run a mutation, you first call `useUpsertMyCounterpartyProfileMutation` within a Vue component and pass it any options that fit your needs. + * When your component renders, `useUpsertMyCounterpartyProfileMutation` returns an object that includes: + * - A mutate function that you can call at any time to execute the mutation + * - Several other properties: https://v4.apollo.vuejs.org/api/use-mutation.html#return + * + * @param options that will be passed into the mutation, supported options are listed on: https://v4.apollo.vuejs.org/guide-composable/mutation.html#options; + * + * @example + * const { mutate, loading, error, onDone } = useUpsertMyCounterpartyProfileMutation({ + * variables: { + * input: // value for 'input' + * }, + * }); + */ +export function useUpsertMyCounterpartyProfileMutation(options: VueApolloComposable.UseMutationOptions | ReactiveFunction> = {}) { + return VueApolloComposable.useMutation(UpsertMyCounterpartyProfileDocument, options); +} +export type UpsertMyCounterpartyProfileMutationCompositionFunctionResult = VueApolloComposable.UseMutationReturn; \ No newline at end of file diff --git a/app/composables/useCounterpartyProfile.ts b/app/composables/useCounterpartyProfile.ts new file mode 100644 index 0000000..5313f66 --- /dev/null +++ b/app/composables/useCounterpartyProfile.ts @@ -0,0 +1,53 @@ +import { useQuery } from '@vue/apollo-composable'; +import { MyCounterpartyProfileDocument } from '~/composables/graphql/generated'; + +function hasText(value: string | null | undefined) { + return Boolean(value && value.trim().length > 0); +} + +export function isCounterpartyProfileComplete(profile: { + companyName?: string | null; + companyFullName?: string | null; + inn?: string | null; + legalAddress?: string | null; + bankName?: string | null; + bik?: string | null; + correspondentAccount?: string | null; + checkingAccount?: string | null; + signerFullName?: string | null; + signerPosition?: string | null; + signerBasis?: string | null; +} | null | undefined) { + if (!profile) { + return false; + } + + return [ + profile.companyName, + profile.companyFullName, + profile.inn, + profile.legalAddress, + profile.bankName, + profile.bik, + profile.correspondentAccount, + profile.checkingAccount, + profile.signerFullName, + profile.signerPosition, + profile.signerBasis, + ].every(hasText); +} + +export function useCounterpartyProfile() { + const query = useQuery(MyCounterpartyProfileDocument); + + const profile = computed(() => query.result.value?.myCounterpartyProfile ?? null); + const isComplete = computed(() => isCounterpartyProfileComplete(profile.value)); + + return { + profile, + isComplete, + loading: query.loading, + error: query.error, + refetch: query.refetch, + }; +} diff --git a/app/pages/cart.vue b/app/pages/cart.vue index c2a0495..91001f6 100644 --- a/app/pages/cart.vue +++ b/app/pages/cart.vue @@ -1,6 +1,7 @@