@weareconceptstudio/account 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  export function useAccountContext(): any;
2
- export function AccountProvider({ fontFamily, shopUrl, children, maxQty, currency, addressType, addressFormFields, useUser }: {
2
+ export function AccountProvider({ fontFamily, shopUrl, children, maxQty, currency, addressType, addressFormFields, useUser, useCart }: {
3
3
  fontFamily?: string;
4
4
  shopUrl?: string;
5
5
  children: any;
@@ -8,5 +8,6 @@ export function AccountProvider({ fontFamily, shopUrl, children, maxQty, currenc
8
8
  addressType: any;
9
9
  addressFormFields: any;
10
10
  useUser: any;
11
+ useCart: any;
11
12
  }): React.JSX.Element;
12
13
  import React from 'react';
@@ -14,13 +14,13 @@ export const useAccountContext = () => {
14
14
  const context = useContext(AccountContext);
15
15
  return context;
16
16
  };
17
- export const AccountProvider = ({ fontFamily = 'core_Font', shopUrl = '/', children, maxQty = 99, currency, addressType, addressFormFields, useUser }) => {
17
+ export const AccountProvider = ({ fontFamily = 'core_Font', shopUrl = '/', children, maxQty = 99, currency, addressType, addressFormFields, useUser, useCart }) => {
18
18
  const { addTranslation } = useTranslation();
19
19
  useEffect(() => {
20
20
  addTranslation(translations, 'prepend');
21
21
  }, []);
22
- return (React.createElement(AccountContext.Provider, { value: { currency, maxQty, shopUrl, useUser } },
23
- React.createElement(AddressProvider, { addressType: addressType, addressFormFields: addressFormFields, useUser: useUser },
22
+ return (React.createElement(AccountContext.Provider, { value: { currency, maxQty, shopUrl, useUser, useCart } },
23
+ React.createElement(AddressProvider, { addressType: addressType, addressFormFields: addressFormFields, useUser: useUser, useCart: useCart },
24
24
  React.createElement(ThemeProvider, { theme: theme },
25
25
  React.createElement(AccountVariables, { fontFamily: fontFamily }),
26
26
  React.createElement(AccountHelperClass, null),
@@ -1,10 +1,3 @@
1
1
  export default OrdersList;
2
- declare function OrdersList({ data, total, pageSize, router, pathname, searchParams }: {
3
- data: any;
4
- total: any;
5
- pageSize: any;
6
- router: any;
7
- pathname: any;
8
- searchParams: any;
9
- }): React.JSX.Element;
2
+ declare function OrdersList(): React.JSX.Element;
10
3
  import React from 'react';
@@ -1,24 +1,34 @@
1
- import React, { useMemo, useCallback } from 'react';
2
- import { createQueryString, Text, useTranslation, useUi } from '@weareconceptstudio/core';
1
+ import React, { useMemo, useState, useEffect, useCallback } from 'react';
2
+ import { Text, useTranslation, useUi, api } from '@weareconceptstudio/core';
3
3
  //* Utils
4
4
  import { handlePriceCheckFunc } from '../../utils/_functions';
5
5
  //* Components
6
6
  import OrderItem from './OrderItem';
7
7
  import Pagination from '../ui/Pagination';
8
8
  import AccountButton from '../ui/AccountButton';
9
+ import EmptyOrders from '../EmptyOrders';
9
10
  //* Style
10
11
  import OrdersListStyle from './style';
11
- // TODO: status change
12
- const OrdersList = ({ data, total, pageSize, router, pathname, searchParams }) => {
12
+ const OrdersList = () => {
13
13
  const { translate } = useTranslation();
14
14
  const { winWidth } = useUi();
15
- const onFilterChange = useCallback((type, typeId, multiple = false) => {
16
- const params = createQueryString({ searchParams, type, typeId, multiple });
17
- if (type === 'page') {
18
- window.scrollTo({ top: 0, behavior: 'smooth' });
19
- }
20
- router.push(pathname + '?' + params, { scroll: false });
21
- }, [searchParams]);
15
+ const [loading, setLoading] = useState(true);
16
+ const [data, setData] = useState([]);
17
+ const [currentPage, setCurrentPage] = useState(1);
18
+ const [pagination, setPagination] = useState({
19
+ total: 0,
20
+ pageSize: 0,
21
+ });
22
+ const getOrders = useCallback((page) => {
23
+ api.get({ url: 'orders', params: { page } }).then((res) => {
24
+ setData(res.orders);
25
+ setPagination(res.pagination);
26
+ setLoading(false);
27
+ });
28
+ }, []);
29
+ useEffect(() => {
30
+ getOrders(currentPage);
31
+ }, [currentPage]);
22
32
  //! List Store
23
33
  const listStore = useMemo(() => {
24
34
  return winWidth >= 768 ? (React.createElement("div", { className: `order-table-wrap` },
@@ -59,11 +69,11 @@ const OrdersList = ({ data, total, pageSize, router, pathname, searchParams }) =
59
69
  React.createElement(AccountButton, { text: 'viewOrder', btnType: `green-small-text`, url: `/account/order-history${item.id}` })))));
60
70
  })));
61
71
  }, [winWidth, data]);
62
- return (React.createElement(OrdersListStyle, null,
72
+ return !loading && data.length > 0 ? (React.createElement(OrdersListStyle, null,
63
73
  React.createElement(Text, { className: `account-p account-p1 account-font-bold account-primary-color1`, text: 'orderHistory' }),
64
74
  React.createElement("div", { className: `order-history-line` }),
65
75
  listStore,
66
76
  React.createElement("div", { className: `pagination-wrap` },
67
- React.createElement(Pagination, { total: total, pageSize: pageSize, onChange: (page) => onFilterChange('page', page) }))));
77
+ React.createElement(Pagination, { activePageState: currentPage, ...pagination, onChange: (page) => setCurrentPage(page) })))) : !loading ? (React.createElement(EmptyOrders, null)) : null;
68
78
  };
69
79
  export default OrdersList;
@@ -11,7 +11,7 @@ const TotalCheckout = memo(({ isShipping, children, confirmation, buttonProps, i
11
11
  const { currency, useUser } = useAccountContext();
12
12
  const { user } = useUser();
13
13
  const savedCards = useMemo(() => {
14
- if (isCheckout) {
14
+ if (user) {
15
15
  let cards = [
16
16
  {
17
17
  label: 'Remember New Card',
@@ -1,13 +1,9 @@
1
1
  import React, { memo, useCallback, useMemo } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { Link, useTranslation } from '@weareconceptstudio/core';
4
- import { useTheme } from 'styled-components';
5
- import theme from '../../../styles/theme';
6
- //* Style
7
4
  import AccountButtonStyle from './style';
8
5
  const AccountButton = memo(({ btnType, text, className, onClick, children, url, customLinkProps, target, type = 'button', disabled = false, svg_icon }) => {
9
6
  const { translate } = useTranslation();
10
- const globalTheme = useTheme();
11
7
  const Component = useMemo(() => (url ? Link : 'button'), [url]);
12
8
  const customProps = useMemo(() => (url ? { ...customLinkProps, url, target } : { type, disabled }), [url, type, disabled]);
13
9
  const classString = classNames('btn-wrap', {
@@ -17,7 +13,7 @@ const AccountButton = memo(({ btnType, text, className, onClick, children, url,
17
13
  const handleClick = useCallback(() => {
18
14
  return !disabled && onClick?.();
19
15
  }, [onClick, disabled]);
20
- return (React.createElement(AccountButtonStyle, { onClick: handleClick, className: classString, theme: theme(globalTheme) },
16
+ return (React.createElement(AccountButtonStyle, { onClick: handleClick, className: classString },
21
17
  React.createElement(Component, { ...customProps },
22
18
  svg_icon || children || translate(text),
23
19
  " ")));
@@ -1,15 +1,12 @@
1
1
  import React from 'react';
2
2
  import { useUi, Text } from '@weareconceptstudio/core';
3
- import { useTheme } from 'styled-components';
4
- import theme from '../../../styles/theme';
5
3
  //* Style
6
4
  import WarningMessageForPopupStyle from './style';
7
5
  //* Components
8
6
  import AccountButton from '../AccountButton';
9
7
  const WarningMessageForPopup = React.memo(({ isDelete = false, isThankYou = false, onRemove, title, description, globalData }) => {
10
8
  const { closePopup } = useUi();
11
- const globalTheme = useTheme();
12
- return (React.createElement(WarningMessageForPopupStyle, { className: 'warning-message-block', theme: theme(globalTheme) },
9
+ return (React.createElement(WarningMessageForPopupStyle, { className: 'warning-message-block' },
13
10
  React.createElement(Text, { tag: `h6`, className: `account-h6 account-font-bold account-primary-color1 warning-message-title`, text: title }),
14
11
  React.createElement(Text, { className: `account-p account-p2 account-font-regular account-primary-color1 confirm-delete-address-text`, text: description }),
15
12
  React.createElement("div", { className: `cancel-remove-wrap ${!isDelete ? 'mobile-margin' : ''}` }, isDelete ? (React.createElement(React.Fragment, null,
@@ -1,15 +1,14 @@
1
1
  import React, { memo as Memo, useState, useCallback } from 'react';
2
2
  import { useUi, Text } from '@weareconceptstudio/core';
3
3
  import { FormBuilder } from '@weareconceptstudio/form';
4
+ import { useAddressContext } from '../AddressProvider';
4
5
  import AccountButton from '../../../components/ui/AccountButton';
5
- import { useTheme } from 'styled-components';
6
- import theme from '../../../styles/theme';
7
6
  //* Icons
8
7
  import { CheckboxIcon, CheckboxCheckedIcon } from '../../../utils/icons';
9
8
  //* Style
10
9
  import AddressFormStyle from './style';
11
- const AddressForm = Memo(({ title, data, formFields, type, createAddress, updateAddress }) => {
12
- const globalTheme = useTheme();
10
+ const AddressForm = Memo(({ title, data, type }) => {
11
+ const { formFields, createAddress, updateAddress } = useAddressContext();
13
12
  const { closePopup } = useUi();
14
13
  //! States
15
14
  const [isChecked, setIsChecked] = useState(data?.is_default || false);
@@ -27,7 +26,7 @@ const AddressForm = Memo(({ title, data, formFields, type, createAddress, update
27
26
  closePopup();
28
27
  }));
29
28
  }, [data, isChecked, createAddress, updateAddress, isDisabled]);
30
- return (React.createElement(AddressFormStyle, { theme: theme(globalTheme), className: 'address-form-block' },
29
+ return (React.createElement(AddressFormStyle, { className: 'address-form-block' },
31
30
  React.createElement(Text, { tag: `h6`, text: title, className: `account-h6 account-font-bold account-primary-color1 address-form-block-title` }),
32
31
  React.createElement(FormBuilder, { formOptions: {
33
32
  initialValues: data,
@@ -23,6 +23,10 @@ const AddressFormStyle = styled.div `
23
23
  .form-item {
24
24
  width: var(--account_antFormItemWidth);
25
25
  padding: 0 calc(var(--account_formItemDistance) / 2);
26
+
27
+ &:last-child {
28
+ --account_antFormItemWidth: 100%;
29
+ }
26
30
  }
27
31
  }
28
32
 
@@ -9,13 +9,13 @@ import WarningMessageForPopup from '../../../components/ui/WarningMessageForPopu
9
9
  import AddressItemStyle from './style';
10
10
  const AddressItem = ({ type, title, data, checkout_review, select_address, onClick }) => {
11
11
  const { openPopup } = useUi();
12
- const { formFields, createAddress, updateAddress, deleteAddress, selectedAddresses, setSelectedAddresses } = useAddressContext();
12
+ const { deleteAddress, selectedAddresses, setSelectedAddresses } = useAddressContext();
13
13
  //! Handle Popups
14
14
  const handleDeletePopup = useCallback(() => {
15
15
  openPopup(React.createElement(WarningMessageForPopup, { isDelete: true, title: 'deleteAddressMessage', description: 'confirmDeleteAddress', onRemove: () => deleteAddress(data.id, data.type) }), { className: 'messagePopup' });
16
16
  }, [data]);
17
17
  const handleEditAddressPopup = useCallback(() => {
18
- openPopup(React.createElement(AddressForm, { title: type === 'billing' ? `updateYourBillingAddress` : type == 'shipping' ? `updateYourShippingAddress` : 'updateYourAddress', data: data, formFields: formFields, createAddress: createAddress, updateAddress: updateAddress }));
18
+ openPopup(React.createElement(AddressForm, { title: type === 'billing' ? `updateYourBillingAddress` : type == 'shipping' ? `updateYourShippingAddress` : 'updateYourAddress', data: data }));
19
19
  }, [data]);
20
20
  return (data && (React.createElement(AddressItemStyle, { className: `item-container` },
21
21
  checkout_review && (React.createElement("div", { className: `change-address-wrap` },
@@ -8,12 +8,12 @@ import AddressItem from '../AddressItem';
8
8
  import AddressForm from '../AddressForm';
9
9
  const AddressWrap = ({ title = 'addresses', addNewText = 'addNewAdd', type, className }) => {
10
10
  const { openPopup } = useUi();
11
- const { formFields, createAddress, updateAddress, addresses } = useAddressContext();
11
+ const { addresses } = useAddressContext();
12
12
  const classString = classNames('address-wrap', {
13
13
  [className]: className,
14
14
  });
15
15
  const handleAddNewAddressPopup = () => {
16
- openPopup(React.createElement(AddressForm, { type: type, title: 'addNewAddress', formFields: formFields, createAddress: createAddress, updateAddress: updateAddress }));
16
+ openPopup(React.createElement(AddressForm, { title: 'addNewAddress', type: type }));
17
17
  };
18
18
  return (React.createElement("div", { className: classString },
19
19
  React.createElement("div", { className: `address-title-container` },
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React from 'react';
2
2
  import { useAddressContext } from '../AddressProvider';
3
3
  import { Text, useUi } from '@weareconceptstudio/core';
4
4
  import AddressForm from '../AddressForm';
@@ -7,9 +7,9 @@ import AccountButton from '../../../components/ui/AccountButton';
7
7
  import SelectAddressStyle from './style';
8
8
  const SelectAddress = ({ type, title }) => {
9
9
  const { openPopup } = useUi();
10
- const { addresses, formFields, hasAddressType, createAddress } = useAddressContext();
10
+ const { addresses, hasAddressType } = useAddressContext();
11
11
  const handleNewAddressPopup = () => {
12
- openPopup(React.createElement(AddressForm, { title: `addNewShippingAddress`, formFields: formFields, createAddress: createAddress, selected: { value: false, type: 'shipping' } }));
12
+ openPopup(React.createElement(AddressForm, { title: `addNewShippingAddress`, selected: { value: false, type: 'shipping' } }));
13
13
  };
14
14
  return (React.createElement(SelectAddressStyle, null,
15
15
  React.createElement("div", { className: `select-address-wrap` },
@@ -1,7 +1,5 @@
1
- import React, { memo as Memo, useState, useCallback } from 'react';
2
- import { Text, useUi } from '@weareconceptstudio/core';
3
- import { useTheme } from 'styled-components';
4
- import theme from '../../../styles/theme';
1
+ import React, { memo as Memo } from 'react';
2
+ import { useUi } from '@weareconceptstudio/core';
5
3
  //* Components
6
4
  import SelectAddress from '../SelectAddress';
7
5
  import AccountButton from '../../../components/ui/AccountButton';
@@ -9,14 +7,13 @@ import AccountButton from '../../../components/ui/AccountButton';
9
7
  import SelectShippingBillingStyle from './style';
10
8
  const SelectShippingBillingPopup = Memo(({ title, type }) => {
11
9
  const { closePopup } = useUi();
12
- const globalTheme = useTheme();
13
10
  // const handleAddressChangeSubmit = useCallback(() => {
14
11
  // let findItem = data.find((item) => item.id === checkedId);
15
12
  // setSelectedAddresses({ ...selectedAddresses, [findItem?.type]: { ...findItem } });
16
13
  // // getCart({ addressId: checkedId });
17
14
  // closePopup();
18
15
  // }, [data, selectedAddresses, checkedId]);
19
- return (React.createElement(SelectShippingBillingStyle, { theme: theme(globalTheme) },
16
+ return (React.createElement(SelectShippingBillingStyle, null,
20
17
  React.createElement(SelectAddress, { type: type, title: title }),
21
18
  React.createElement("div", { className: `cancel-and-save-wrap` },
22
19
  React.createElement(AccountButton, { btnType: `green-large-text`, text: `cancel`, onClick: closePopup }),
@@ -19,6 +19,10 @@ const ShippingBillingFormStyle = styled.div `
19
19
  .form-item {
20
20
  width: var(--account_antFormItemWidth);
21
21
  padding: 0 calc(var(--account_formItemDistance) / 2);
22
+
23
+ &:last-child {
24
+ --account_antFormItemWidth: 100%;
25
+ }
22
26
  }
23
27
  }
24
28
 
@@ -1,6 +1,5 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { Text, Link, useUi, Page } from '@weareconceptstudio/core';
3
- //* Style
4
3
  import AccountStyle from './style';
5
4
  const AccountTemplate = ({ isFullWidth = false, menuOptions = [], children, onSignOut }) => {
6
5
  const { winWidth } = useUi();
@@ -1,20 +1,8 @@
1
- import React, { useEffect, useState } from 'react';
2
- //* Style
1
+ import React from 'react';
2
+ import { OrdersList } from '../../components';
3
3
  import OrderHistoryTemplateStyle from './style';
4
- //* Components
5
- import { EmptyOrders, OrdersList } from '../../components';
6
- import { api } from '@weareconceptstudio/core';
7
- // TODO:
8
- const total = 0, pageSize = 0;
9
4
  const OrderHistoryTemplate = () => {
10
- const [data, setData] = useState();
11
- const [loading, setLoading] = useState(true);
12
- useEffect(() => {
13
- api.get({ url: 'orders' }).then((res) => {
14
- setData(res.orders);
15
- setLoading(false);
16
- });
17
- }, []);
18
- return !loading ? (React.createElement(OrderHistoryTemplateStyle, null, data?.length > 0 ? (React.createElement(OrdersList, { data: data, total: total, pageSize: pageSize })) : (React.createElement(EmptyOrders, null)))) : null;
5
+ return (React.createElement(OrderHistoryTemplateStyle, null,
6
+ React.createElement(OrdersList, null)));
19
7
  };
20
8
  export default OrderHistoryTemplate;
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import React from 'react';
2
+ import React, { useEffect } from 'react';
3
3
  import { Page, Text, Container, useTranslation } from '@weareconceptstudio/core';
4
4
  import { Sequence } from '../../components';
5
5
  import Button from '../../components/ui/AccountButton';
@@ -7,8 +7,12 @@ import ThankYouMessageStyle from './style';
7
7
  import { useAccountContext } from '../../AccountProvider';
8
8
  import { confirmImage } from './icons';
9
9
  const ThankYouTemplate = ({ orderNumber }) => {
10
- const { shopUrl } = useAccountContext();
10
+ const { shopUrl, useCart } = useAccountContext();
11
11
  const { translate } = useTranslation();
12
+ const cart = useCart();
13
+ useEffect(() => {
14
+ cart.clearCart();
15
+ }, []);
12
16
  return (React.createElement(Page, { className: 'use-account' },
13
17
  React.createElement(ThankYouMessageStyle, null,
14
18
  React.createElement(Container, null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weareconceptstudio/account",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Concept Studio Account",
5
5
  "author": "Concept Studio",
6
6
  "license": "ISC",