Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout implovements #28

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading