Skip to content

Commit

Permalink
[shopsys] register company after order is more user friendly on b2b d…
Browse files Browse the repository at this point in the history
…omain (#3546)
  • Loading branch information
grossmannmartin authored Nov 6, 2024
2 parents 123022f + 0dd85f3 commit f8b75d9
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,3 @@ CustomerUserQuery:
type: 'CustomerUser'
resolve: "@=query('nullableCurrentCustomerUserQuery')"
description: "Returns currently logged in customer user"
isCustomerUserRegistered:
type: Boolean!
args:
email:
type: String!
validation:
- NotBlank:
message: "Please enter valid email"
- Email:
message: "Please enter valid email"
- Length:
max: 255
maxMessage: "Email cannot be longer than {{ limit }} characters"
resolve: "@=query('isCustomerUserRegisteredQuery', args['email'])"
description: "Check if email is registered"
2 changes: 2 additions & 0 deletions app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,8 @@ type Query {
): Complaint!
"Returns list of complaints that can be paginated using `first`, `last`, `before` and `after` keywords"
complaints(after: String, before: String, first: Int, last: Int, searchInput: SearchInput): ComplaintConnection!
"Check if customer can be registered with provided data"
couldBeCustomerRegisteredQuery(companyNumber: String = null, email: String!): Boolean!
"Returns available countries"
countries: [Country!]!
"Returns currently logged in customer user"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const useHandleCreateOrderResult = () => {
if (wasOrderCreated && createdOrder) {
const orderConfirmationUrlQuery: OrderConfirmationUrlQuery = {
orderUuid: createdOrder.uuid,
companyNumber: user?.companyNumber ?? formValues.companyNumber,
orderEmail: user?.email ?? formValues.email,
orderPaymentType: createdOrder.payment.type,
orderPaymentStatusPageValidityHash: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Form, FormBlockWrapper, FormContentWrapper } from 'components/Forms/For
import { FormLine } from 'components/Forms/Lib/FormLine';
import { PasswordInputControlled } from 'components/Forms/TextInput/PasswordInputControlled';
import { TIDs } from 'cypress/tids';
import { useIsCustomerUserRegisteredQuery } from 'graphql/requests/customer/queries/IsCustomerUserRegisteredQuery.generated';
import { useCouldBeCustomerRegisteredQuery } from 'graphql/requests/customer/queries/CouldBeCustomerRegisteredQuery.generated';
import { GtmMessageOriginType } from 'gtm/enums/GtmMessageOriginType';
import Trans from 'next-translate/Trans';
import useTranslation from 'next-translate/useTranslation';
Expand All @@ -29,15 +29,16 @@ export const RegistrationAfterOrder: FC = () => {
const { registerByOrder } = useRegistration();
const isInvalidRegistrationRef = useRef(false);
const { query } = useRouter();
const { orderUuid, orderEmail, orderUrlHash } = query as OrderConfirmationUrlQuery;
const { orderUuid, companyNumber, orderEmail, orderUrlHash } = query as OrderConfirmationUrlQuery;
const isUserLoggedIn = useIsUserLoggedIn();

useErrorPopup(formProviderMethods, formMeta.fields, undefined, GtmMessageOriginType.order_confirmation_page);

const [{ data: isCustomerUserRegisteredData, fetching: isInformationAboutUserRegistrationFetching }] =
useIsCustomerUserRegisteredQuery({
const [{ data: couldBeCustomerRegisteredData, fetching: isInformationAboutUserRegistrationFetching }] =
useCouldBeCustomerRegisteredQuery({
variables: {
email: orderEmail!,
companyNumber: companyNumber!,
},
pause: !orderEmail,
});
Expand Down Expand Up @@ -72,7 +73,7 @@ export const RegistrationAfterOrder: FC = () => {
isUserLoggedIn ||
!orderUuid ||
isInformationAboutUserRegistrationFetching ||
isCustomerUserRegisteredData?.isCustomerUserRegistered === true
couldBeCustomerRegisteredData?.couldBeCustomerRegisteredQuery === false
) {
return null;
}
Expand Down
19 changes: 19 additions & 0 deletions storefront/graphql/docs/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,25 @@ Returns list of complaints that can be paginated using `first`, `last`, `before`
<td></td>
</tr>
<tr>
<td colspan="2" valign="top"><strong>couldBeCustomerRegisteredQuery</strong></td>
<td valign="top"><a href="#boolean">Boolean</a>!</td>
<td>

Check if customer can be registered with provided data

</td>
</tr>
<tr>
<td colspan="2" align="right" valign="top">companyNumber</td>
<td valign="top"><a href="#string">String</a></td>
<td></td>
</tr>
<tr>
<td colspan="2" align="right" valign="top">email</td>
<td valign="top"><a href="#string">String</a>!</td>
<td></td>
</tr>
<tr>
<td colspan="2" valign="top"><strong>countries</strong></td>
<td valign="top">[<a href="#country">Country</a>!]!</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import * as Types from '../../../types';

import gql from 'graphql-tag';
import * as Urql from 'urql';
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type TypeCouldBeCustomerRegisteredQueryVariables = Types.Exact<{
email: Types.Scalars['String']['input'];
companyNumber: Types.InputMaybe<Types.Scalars['String']['input']>;
}>;


export type TypeCouldBeCustomerRegisteredQuery = { __typename?: 'Query', couldBeCustomerRegisteredQuery: boolean };


export interface PossibleTypesResultData {
possibleTypes: {
[key: string]: string[]
}
}
const result: PossibleTypesResultData = {
"possibleTypes": {
"Advert": [
"AdvertCode",
"AdvertImage"
],
"ArticleInterface": [
"ArticleSite",
"BlogArticle"
],
"Breadcrumb": [
"ArticleSite",
"BlogArticle",
"BlogCategory",
"Brand",
"Category",
"Flag",
"MainVariant",
"RegularProduct",
"Store",
"Variant"
],
"CustomerUser": [
"CompanyCustomerUser",
"RegularCustomerUser"
],
"Hreflang": [
"BlogArticle",
"BlogCategory",
"Brand",
"Flag",
"MainVariant",
"RegularProduct",
"SeoPage",
"Variant"
],
"NotBlogArticleInterface": [
"ArticleLink",
"ArticleSite"
],
"ParameterFilterOptionInterface": [
"ParameterCheckboxFilterOption",
"ParameterColorFilterOption",
"ParameterSliderFilterOption"
],
"Product": [
"MainVariant",
"RegularProduct",
"Variant"
],
"ProductListable": [
"Brand",
"Category",
"Flag"
],
"Slug": [
"ArticleSite",
"BlogArticle",
"BlogCategory",
"Brand",
"Category",
"Flag",
"MainVariant",
"RegularProduct",
"Store",
"Variant"
]
}
};
export default result;


export const CouldBeCustomerRegisteredQueryDocument = gql`
query CouldBeCustomerRegisteredQuery($email: String!, $companyNumber: String) {
couldBeCustomerRegisteredQuery(email: $email, companyNumber: $companyNumber)
}
`;

export function useCouldBeCustomerRegisteredQuery(options: Omit<Urql.UseQueryArgs<TypeCouldBeCustomerRegisteredQueryVariables>, 'query'>) {
return Urql.useQuery<TypeCouldBeCustomerRegisteredQuery, TypeCouldBeCustomerRegisteredQueryVariables>({ query: CouldBeCustomerRegisteredQueryDocument, ...options });
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query CouldBeCustomerRegisteredQuery($email: String!, $companyNumber: String) {
couldBeCustomerRegisteredQuery(email: $email, companyNumber: $companyNumber)
}
8 changes: 8 additions & 0 deletions storefront/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,8 @@ export type TypeQuery = {
complaint: TypeComplaint;
/** Returns list of complaints that can be paginated using `first`, `last`, `before` and `after` keywords */
complaints: TypeComplaintConnection;
/** Check if customer can be registered with provided data */
couldBeCustomerRegisteredQuery: Scalars['Boolean']['output'];
/** Returns available countries */
countries: Array<TypeCountry>;
/** Returns currently logged in customer user */
Expand Down Expand Up @@ -2596,6 +2598,12 @@ export type TypeQueryComplaintsArgs = {
};


export type TypeQueryCouldBeCustomerRegisteredQueryArgs = {
companyNumber?: InputMaybe<Scalars['String']['input']>;
email: Scalars['String']['input'];
};


export type TypeQueryFlagArgs = {
urlSlug: InputMaybe<Scalars['String']['input']>;
uuid: InputMaybe<Scalars['Uuid']['input']>;
Expand Down
1 change: 1 addition & 0 deletions storefront/pages/order-confirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getInternationalizedStaticUrls } from 'utils/staticUrls/getInternationa

export type OrderConfirmationUrlQuery = {
orderUuid: string | undefined;
companyNumber: string | undefined;
orderEmail: string | undefined;
orderPaymentType: string | undefined;
orderUrlHash?: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions storefront/public/locales/cs/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"Currently, it is not possible to purchase any variant of this product.": "Aktuálně není možné koupit ani jednu variantu produktu.",
"Customer": "Zákazník",
"Customer information": "Informace o zákazníkovi",
"Customer is already registered.": "Zákazník je již registrován.",
"Customer users": "Uživatelé",
"Customized E-shop by": "E-shop na míru od",
"Czechia": "Česko",
Expand Down
1 change: 1 addition & 0 deletions storefront/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"Currently, it is not possible to purchase any variant of this product.": "Currently, it is not possible to purchase any variant of this product.",
"Customer": "Customer",
"Customer information": "Customer information",
"Customer is already registered.": "Customer is already registered.",
"Customer users": "Users",
"Customized E-shop by": "Customized E-shop by",
"Czechia": "Czechia",
Expand Down
1 change: 1 addition & 0 deletions storefront/public/locales/sk/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"Currently, it is not possible to purchase any variant of this product.": "Aktuálne nie je možné kúpiť ani jeden variant produktu.",
"Customer": "Zákazník",
"Customer information": "Informácie o zákazníkovi",
"Customer is already registered.": "Zákazník je už zaregistrovaný.",
"Customer users": "Užívatelia",
"Customized E-shop by": "E-shop na mieru od",
"Czechia": "Česko",
Expand Down
2 changes: 1 addition & 1 deletion storefront/schema-compressed.graphql.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions storefront/utils/errors/applicationErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const ApplicationErrors = {
'register-by-order-is-not-possible': 'flash-message',
'too-many-login-attempts': 'flash-message',
'invalid-account-or-password': 'no-flash-message',
'company-already-registered': 'flash-message',
} as const;

type KeysMatching<T, V extends ApplicationErrorVerbosityLevel> = {
Expand Down
1 change: 1 addition & 0 deletions storefront/utils/errors/errorMessageMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const getErrorMessageTranslationString = (errorCode: FlashMessageKeys, t: Transl
'invalid-quantity': t('Complaint item quantity exceeds the order item quantity.'),
'register-by-order-is-not-possible': t('It was not possible to create register new user from the order'),
'too-many-login-attempts': t('Too many login attempts. Try again later.'),
'company-already-registered': t('Customer is already registered.'),
};

return ERROR_MESSAGES[errorCode];
Expand Down

0 comments on commit f8b75d9

Please sign in to comment.