Skip to content

Commit

Permalink
Merge pull request #28 from kirill-zhirnov/20231111_new_checkout_logi…
Browse files Browse the repository at this point in the history
…n_flow

checkout implovements
  • Loading branch information
kirill-zhirnov authored Nov 13, 2023
2 parents 4f36210 + a31bcb6 commit 38fd711
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/components/ContactInformationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import LoginIcon from '@mui/icons-material/Login';
import {LoginFormView} from './LoginForm';
import clsx from 'clsx';
import {useTranslation} from 'react-i18next';
import {setLoggedInCustomer} from '../redux/actions/user';

export default function ContactInformationForm() {
const [viewMode, setViewMode] = useState<TViewMode>(TViewMode.contact);
Expand Down Expand Up @@ -95,7 +96,8 @@ export function ContactFormView({setViewMode}: { setViewMode: (mode: TViewMode)
type={'email'}
required={required}
fullWidth
{...fieldAttrs<IContactInformationFormValues>('email', formikProps)}
disabled={Boolean(loggedInCustomer)}
{...fieldAttrs<IContactInformationFormValues>('email', formikProps, loggedInCustomer ? t('contactForm.youAreLoggedIn') : '')}
/>
}
{type === 'phone' &&
Expand All @@ -108,6 +110,15 @@ export function ContactFormView({setViewMode}: { setViewMode: (mode: TViewMode)
}
</Grid>
)}
{(accountPolicy === TCheckoutAccountPolicy.guestAndLogin && !loggedInCustomer) &&
<Grid item
xs={12}
>
<FormControlLabel control={
<Checkbox {...checkAttrs('register_me', formikProps)} />
} label={t('contactForm.registerMe')}/>
</Grid>
}
{excludedFields.includes('receive_marketing_info') &&
<Grid item
xs={12}
Expand Down Expand Up @@ -168,9 +179,13 @@ const useSaveContactInfo = () => {
const promise = api!.checkout.saveContactsData({
order_id,
...rest,
receive_marketing_info: receive_marketing_info ? '1' : undefined
receive_marketing_info: receive_marketing_info
})
.then(({customer}) => {
.then(({customer, authToken}) => {
if (customer && authToken) {
dispatch(setLoggedInCustomer(customer, authToken));
}

dispatch(setOrdersCustomer(customer));
dispatch(addFilledStep({step: TCheckoutStep.contactInfo}));

Expand Down Expand Up @@ -221,7 +236,8 @@ const getFieldsList = (contactFields: ICheckoutSettingsContactFields) => {
const getInitialValues = (order: IOrder, loggedInCustomer: ICustomer | null) => {
const {customer} = order;
const initialValues: IContactInformationFormValues = {
receive_marketing_info: true
receive_marketing_info: true,
register_me: false
};

if (loggedInCustomer) {
Expand All @@ -244,6 +260,7 @@ export interface IContactInformationFormValues {
email?: string;
phone?: string;
receive_marketing_info?: boolean;
register_me?: boolean;
}

export enum TViewMode {
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"phone": "Phone",
"receiveMarketingInfo": "Email me with news and offers",
"continueToShipping": "Continue to shipping",
"continueToPayment": "Continue to payment"
"continueToPayment": "Continue to payment",
"registerMe": "Register Me",
"youAreLoggedIn": "You are logged in"
},
"loginForm": {
"pageTitle": "Checkout: Login",
Expand Down

0 comments on commit 38fd711

Please sign in to comment.