-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove redux and create custom state management
- Loading branch information
Showing
23 changed files
with
334 additions
and
342 deletions.
There are no files selected for viewing
39 changes: 0 additions & 39 deletions
39
templates/frontOffice/modern/assets/js/redux/modules/checkout.ts
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
templates/frontOffice/modern/assets/js/redux/modules/visibility.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { createGlobalState } from 'react-use'; | ||
|
||
const initialState: { | ||
mode: string | null; | ||
phoneNumberValid: boolean; | ||
checkoutStep: number; | ||
deliveryAddressId?: number; | ||
deliveryModuleId?: number; | ||
deliveryModuleOption?: string; | ||
} = { | ||
mode: null, | ||
phoneNumberValid: false, | ||
checkoutStep: 1 | ||
}; | ||
|
||
export const globalCheckoutState = createGlobalState(initialState); | ||
|
||
export const useGlobalCheckout = () => { | ||
const [checkoutState, setCheckout] = globalCheckoutState(); | ||
|
||
const setMode = (mode: string) => { | ||
let checkout = { ...checkoutState }; | ||
|
||
checkout.mode = mode; | ||
|
||
checkout.deliveryAddressId = initialState.deliveryAddressId; | ||
checkout.deliveryModuleId = initialState.deliveryModuleId; | ||
checkout.deliveryModuleOption = initialState.deliveryModuleOption; | ||
|
||
setCheckout(checkout); | ||
}; | ||
|
||
const setPhoneNumberValid = (value: boolean) => { | ||
let checkout = { ...checkoutState }; | ||
|
||
checkout.phoneNumberValid = value; | ||
setCheckout(checkout); | ||
}; | ||
|
||
const setCheckoutStep = (step: number) => { | ||
let checkout = { ...checkoutState }; | ||
|
||
checkout.checkoutStep = step; | ||
setCheckout(checkout); | ||
}; | ||
|
||
return { | ||
checkoutState: checkoutState, | ||
actions: { | ||
setMode: setMode, | ||
setPhoneNumberValid: setPhoneNumberValid, | ||
setCheckoutStep: setCheckoutStep | ||
} | ||
}; | ||
}; |
74 changes: 74 additions & 0 deletions
74
templates/frontOffice/modern/assets/js/state/visibility.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createGlobalState } from 'react-use'; | ||
|
||
const initialState: { | ||
cart: boolean; | ||
login: boolean; | ||
redirectionToCheckout: boolean; | ||
} = { | ||
cart: false, | ||
login: false, | ||
redirectionToCheckout: false | ||
}; | ||
|
||
export const globalVisibility = createGlobalState(initialState); | ||
|
||
export const useGlobalVisibility = () => { | ||
const [visibilityState, setVisibility] = globalVisibility(); | ||
|
||
const hideCart = () => { | ||
let visibility = { ...visibilityState }; | ||
|
||
visibility.cart = false; | ||
setVisibility(visibility); | ||
}; | ||
const showCart = () => { | ||
let visibility = { ...visibilityState }; | ||
|
||
visibility.cart = true; | ||
setVisibility(visibility); | ||
}; | ||
const toggleCart = () => { | ||
let visibility = { ...visibilityState }; | ||
|
||
visibility.cart = !visibility.cart; | ||
setVisibility(visibility); | ||
}; | ||
|
||
const showLogin = (redirectionToCheckout: boolean) => { | ||
let visibility = { ...visibilityState }; | ||
|
||
visibility.login = true; | ||
visibility.redirectionToCheckout = redirectionToCheckout || false; | ||
console.log('show'); | ||
setVisibility(visibility); | ||
}; | ||
|
||
const hideLogin = (redirectionToCheckout: boolean) => { | ||
let visibility = { ...visibilityState }; | ||
|
||
visibility.login = false; | ||
visibility.redirectionToCheckout = redirectionToCheckout || false; | ||
console.log('hide'); | ||
setVisibility(visibility); | ||
}; | ||
|
||
const toggleLogin = () => { | ||
let visibility = { ...visibilityState }; | ||
|
||
visibility.login = !visibility.login; | ||
console.log('toggle', visibility); | ||
setVisibility(visibility); | ||
}; | ||
|
||
return { | ||
visibilityState: visibilityState, | ||
actions: { | ||
hideCart: hideCart, | ||
showCart: showCart, | ||
toggleCart: toggleCart, | ||
showLogin: showLogin, | ||
hideLogin: hideLogin, | ||
toggleLogin: toggleLogin | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.