diff --git a/packages/p2p/src/pages/my-ads/create-ad-form.scss b/packages/p2p/src/pages/my-ads/create-ad-form.scss
index 88e0b62b7f0b..a15ec8fee654 100644
--- a/packages/p2p/src/pages/my-ads/create-ad-form.scss
+++ b/packages/p2p/src/pages/my-ads/create-ad-form.scss
@@ -10,19 +10,6 @@
}
}
- .dc-input__wrapper {
- max-width: 67.2rem; // TODO: Kill these fixed widths.
- margin-top: 2.1rem;
-
- @include mobile {
- max-width: 90vw;
-
- .create-ad-form__field {
- margin-bottom: 0;
- }
- }
- }
-
&__label {
&--focused {
color: var(--text-prominent);
@@ -35,31 +22,6 @@
max-width: 67.2rem;
padding: 1.2rem 0;
}
-
- &--text {
- display: flex;
- flex-direction: column;
- margin-top: 3.2rem;
- padding-bottom: 1rem;
- }
- }
-
- &__radio-group {
- display: flex;
- margin-top: unset;
- padding-bottom: 1.2rem;
-
- .dc-radio-group__circle {
- border: 2px solid var(--border-hover);
-
- &--selected {
- border: 4px solid var(--brand-red-coral);
- }
- }
-
- @include mobile {
- padding: 0.5rem 0;
- }
}
&__scrollbar {
@@ -94,97 +56,6 @@
}
}
- &__container {
- display: flex;
- height: 8rem;
- justify-content: space-between;
- width: 67.2rem;
-
- .dc-input {
- margin-bottom: 2.1rem;
- margin-top: 2.1rem;
-
- &__container {
- padding: 0 1rem;
- }
- &--hint {
- margin-bottom: 0;
- }
- &__wrapper {
- margin-top: 0;
- }
- }
-
- @include mobile {
- flex-direction: column;
- height: unset;
- width: unset;
-
- .dc-input {
- &__wrapper {
- margin-bottom: 5rem;
- }
- }
- }
- }
-
- &__field {
- height: 4rem;
- margin-bottom: 0;
- margin-left: 0;
- width: 32.4rem;
-
- @include mobile {
- width: inherit;
- }
-
- &--contact-details {
- margin-bottom: 5.9rem;
-
- @include mobile {
- margin-bottom: 3.7rem;
- }
- }
- &--single {
- width: 18.9rem;
- }
- &--textarea {
- height: 9.6rem;
- margin-bottom: 0;
- width: 67.2rem;
-
- @include mobile {
- height: 9.8rem;
- width: 90vw;
- }
-
- .dc-input {
- &__hint {
- top: 9.7rem;
- }
-
- &___counter {
- top: 9.7rem;
- right: 0rem;
-
- @include mobile {
- display: flex;
- right: 0;
- }
- }
-
- &__textarea {
- padding-top: 1rem;
- padding-left: 0;
- }
-
- &__container {
- height: 9.6rem;
- }
- }
- }
- }
-
&__button {
margin-left: 0.8rem;
}
@@ -194,6 +65,7 @@
background-color: var(--general-main-1);
display: flex;
justify-content: flex-end;
+ column-gap: 0.8rem;
@include mobile {
border-top: 2px solid var(--general-section-1);
@@ -203,10 +75,14 @@
}
}
- &__offer-amt {
- &__sell_ad {
- margin-top: 0 !important;
- }
+ &__progress-bar {
+ width: 5.6rem;
+ height: 5.6rem;
+ border-radius: 50%;
+ border: 2px solid;
+ display: flex;
+ align-items: center;
+ justify-content: center;
}
&__dropdown {
diff --git a/packages/p2p/src/pages/my-ads/create-ad.jsx b/packages/p2p/src/pages/my-ads/create-ad.jsx
index fc8bf3f9524f..c00fd63c1584 100644
--- a/packages/p2p/src/pages/my-ads/create-ad.jsx
+++ b/packages/p2p/src/pages/my-ads/create-ad.jsx
@@ -1,13 +1,11 @@
import * as React from 'react';
import { Loading } from '@deriv/components';
import { observer } from 'mobx-react-lite';
-import { localize } from 'Components/i18next';
-import PageReturn from 'Components/page-return';
import CopyAdvertForm from 'Pages/my-ads/copy-advert-form';
+import CreateAdForm from 'Pages/my-ads/create-ad-form';
import { useStores } from 'Stores';
-import CreateAdForm from './create-ad-form.jsx';
-const CreateAd = () => {
+const CreateAd = ({ country_list }) => {
const { my_ads_store } = useStores();
const {
is_form_loading,
@@ -28,11 +26,10 @@ const CreateAd = () => {
}
return (
-
{should_copy_advert ? (
-
+
) : (
-
+
)}
);
diff --git a/packages/p2p/src/pages/my-ads/edit-ad-form-payment-methods.jsx b/packages/p2p/src/pages/my-ads/edit-ad-form-payment-methods.jsx
index 01039dd44247..e775bbd0eb0c 100755
--- a/packages/p2p/src/pages/my-ads/edit-ad-form-payment-methods.jsx
+++ b/packages/p2p/src/pages/my-ads/edit-ad-form-payment-methods.jsx
@@ -28,15 +28,6 @@ const EditAdFormPaymentMethods = ({ is_sell_advert, selected_methods, setSelecte
touched(true);
};
- React.useEffect(() => {
- return () => {
- my_ads_store.payment_method_ids = [];
- my_ads_store.payment_method_names = [];
- };
-
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
-
if (is_sell_advert) {
if (p2p_advertiser_payment_methods?.length) {
return (
diff --git a/packages/p2p/src/pages/my-ads/edit-ad-form.jsx b/packages/p2p/src/pages/my-ads/edit-ad-form.jsx
index d6cdeb0d77ba..dcd92e417be8 100644
--- a/packages/p2p/src/pages/my-ads/edit-ad-form.jsx
+++ b/packages/p2p/src/pages/my-ads/edit-ad-form.jsx
@@ -1,22 +1,14 @@
import * as React from 'react';
-import classNames from 'classnames';
-import { Formik, Field, Form } from 'formik';
-import { Button, Div100vhContainer, Input, Modal, Text, ThemedScrollbars } from '@deriv/components';
+import { Formik, Form } from 'formik';
+import { Div100vhContainer, ThemedScrollbars } from '@deriv/components';
import { useP2PSettings } from '@deriv/hooks';
-import { formatMoney, isDesktop, isMobile } from '@deriv/shared';
+import { isMobile } from '@deriv/shared';
import { observer } from 'mobx-react-lite';
-import { Localize, localize } from 'Components/i18next';
-import PageReturn from 'Components/page-return';
-import { api_error_codes } from 'Constants/api-error-codes';
import { buy_sell } from 'Constants/buy-sell';
import { useStores } from 'Stores';
import { ad_type } from 'Constants/floating-rate';
-import FloatingRate from 'Components/floating-rate';
-import { generateErrorDialogTitle, generateErrorDialogBody } from 'Utils/adverts';
-import EditAdFormPaymentMethods from './edit-ad-form-payment-methods.jsx';
-import EditAdSummary from './edit-ad-summary.jsx';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';
-import OrderTimeSelection from './order-time-selection';
+import AdWizard from './ad-wizard';
import './edit-ad-form.scss';
const EditAdFormWrapper = ({ children }) => {
@@ -27,15 +19,19 @@ const EditAdFormWrapper = ({ children }) => {
return children;
};
-const EditAdForm = () => {
- const { general_store, my_ads_store, my_profile_store } = useStores();
+const EditAdForm = ({ country_list }) => {
+ const { my_ads_store, my_profile_store } = useStores();
+ const steps = [
+ { header: { title: 'Edit ad type and amount' } },
+ { header: { title: 'Edit payment details' } },
+ { header: { title: 'Edit ad conditions' } },
+ ];
const {
- account_currency,
amount_display,
contact_info,
description,
- local_currency,
+ eligible_countries,
max_order_amount_display,
min_order_amount_display,
order_expiry_period,
@@ -49,7 +45,6 @@ const EditAdForm = () => {
const is_buy_advert = type === buy_sell.BUY;
const [selected_methods, setSelectedMethods] = React.useState([]);
- const [is_payment_method_touched, setIsPaymentMethodTouched] = React.useState(false);
const { useRegisterModalProps } = useModalManagerContext();
const { p2p_settings } = useP2PSettings();
@@ -71,44 +66,8 @@ const EditAdForm = () => {
return rate_display;
};
- const payment_methods_changed = is_buy_advert
- ? !(
- !!payment_method_names &&
- selected_methods?.every(pm => {
- const method = my_profile_store.getPaymentMethodDisplayName(pm);
- return payment_method_names.includes(method);
- }) &&
- selected_methods.length === payment_method_names.length
- )
- : !(
- !!payment_method_details &&
- selected_methods.every(pm => Object.keys(payment_method_details).includes(pm)) &&
- selected_methods.length === Object.keys(payment_method_details).length
- );
-
- const handleEditAdFormCancel = is_form_edited => {
- if (is_form_edited || payment_methods_changed) {
- general_store.showModal({
- key: 'AdCancelModal',
- props: {
- confirm_label: localize("Don't cancel"),
- message: localize('If you choose to cancel, the edited details will be lost.'),
- onConfirm: () => my_ads_store.setShowEditAdForm(false),
- title: localize('Cancel your edits?'),
- },
- });
- } else {
- my_ads_store.setShowEditAdForm(false);
- }
- };
-
- const is_api_error = [api_error_codes.ADVERT_SAME_LIMITS, api_error_codes.DUPLICATE_ADVERT].includes(
- my_ads_store.error_code
- );
-
React.useEffect(() => {
my_profile_store.getAdvertiserPaymentMethods();
- my_ads_store.setIsEditAdErrorModalVisible(false);
my_ads_store.setEditAdFormError('');
if (payment_method_names && !payment_method_details) {
@@ -128,29 +87,25 @@ const EditAdForm = () => {
my_ads_store.payment_method_ids.push(pm[0]);
});
}
- if (my_ads_store.required_ad_type !== rate_type) {
- const is_payment_method_available =
- !!Object.keys({ ...payment_method_details }).length ||
- !!Object.values({ ...payment_method_names }).length;
- setIsPaymentMethodTouched(is_payment_method_available);
- }
return () => {
my_ads_store.setApiErrorCode(null);
my_ads_store.setShowEditAdForm(false);
+ my_ads_store.payment_method_ids = [];
+ my_ads_store.payment_method_names = [];
+ my_ads_store.setMinJoinDays(0);
+ my_ads_store.setMinCompletionRate(0);
+ my_ads_store.setP2pAdvertInformation({});
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
- my_ads_store.setShowEditAdForm(false)}
- page_title={localize('Edit {{ad_type}} ad', { ad_type: type })}
- />
{
validate={my_ads_store.validateEditAdForm}
validateOnMount
>
- {({ dirty, errors, handleChange, isSubmitting, isValid, setFieldTouched, touched, values }) => {
- const is_sell_advert = values.type === buy_sell.SELL;
- // Form should not be checked for value change when ad switch is triggered
- const check_dirty =
- my_ads_store.required_ad_type === rate_type
- ? dirty || is_payment_method_touched
- : is_payment_method_touched;
+ {() => {
return (
@@ -457,28 +144,6 @@ const EditAdForm = () => {
);
}}
-
-
-
- {generateErrorDialogBody(my_ads_store.error_code, my_ads_store.edit_ad_form_error)}
-
-
-
-
-
);
};
diff --git a/packages/p2p/src/pages/my-ads/edit-ad-form.scss b/packages/p2p/src/pages/my-ads/edit-ad-form.scss
index d59875f2885a..87585459161b 100644
--- a/packages/p2p/src/pages/my-ads/edit-ad-form.scss
+++ b/packages/p2p/src/pages/my-ads/edit-ad-form.scss
@@ -11,9 +11,6 @@
}
.dc-input__wrapper {
- max-width: 67.2rem; // TODO: Kill these fixed widths.
- margin-top: 2.1rem;
-
@include mobile {
max-width: 90vw;
diff --git a/packages/p2p/src/pages/my-ads/edit-ad.jsx b/packages/p2p/src/pages/my-ads/edit-ad.jsx
index f27bd25147e1..067633eea939 100644
--- a/packages/p2p/src/pages/my-ads/edit-ad.jsx
+++ b/packages/p2p/src/pages/my-ads/edit-ad.jsx
@@ -4,12 +4,16 @@ import { observer } from 'mobx-react-lite';
import { useStores } from 'Stores';
import EditAdForm from './edit-ad-form.jsx';
-const EditAd = () => {
+const EditAd = ({ country_list }) => {
const { my_ads_store } = useStores();
return (
- {my_ads_store.is_form_loading ? : }
+ {my_ads_store.is_form_loading ? (
+
+ ) : (
+
+ )}
);
};
diff --git a/packages/p2p/src/pages/my-ads/my-ads-row-renderer.jsx b/packages/p2p/src/pages/my-ads/my-ads-row-renderer.jsx
index 99f3ba413929..6549c8a82807 100644
--- a/packages/p2p/src/pages/my-ads/my-ads-row-renderer.jsx
+++ b/packages/p2p/src/pages/my-ads/my-ads-row-renderer.jsx
@@ -61,7 +61,7 @@ const MyAdsRowDropdown = ({
);
};
-const MyAdsRowRenderer = observer(({ row: advert, table_ref }) => {
+const MyAdsRowRenderer = observer(({ country_list, row: advert, table_ref }) => {
const {
ui: { is_desktop },
} = useStore();
@@ -136,14 +136,14 @@ const MyAdsRowRenderer = observer(({ row: advert, table_ref }) => {
};
const onClickCopy = () => {
if (p2p_settings.rate_type === rate_type) {
- my_ads_store.onClickCopy(id, is_desktop);
+ my_ads_store.onClickCopy(country_list, id, is_desktop);
} else {
general_store.showModal({
key: 'MyAdsFloatingRateSwitchModal',
props: {
onSwitch: () => {
hideModal();
- my_ads_store.onClickCopy(id, is_desktop);
+ my_ads_store.onClickCopy(country_list, id, is_desktop);
},
},
});
diff --git a/packages/p2p/src/pages/my-ads/my-ads-table.jsx b/packages/p2p/src/pages/my-ads/my-ads-table.jsx
index 38373d76b750..6a18cbb7cc6b 100644
--- a/packages/p2p/src/pages/my-ads/my-ads-table.jsx
+++ b/packages/p2p/src/pages/my-ads/my-ads-table.jsx
@@ -20,7 +20,7 @@ const getHeaders = offered_currency => [
{ text: '' }, // empty header for delete and archive icons
];
-const MyAdsTable = ({ table_ref }) => {
+const MyAdsTable = ({ country_list, table_ref }) => {
const { general_store, my_ads_store } = useStores();
const {
client: { currency },
@@ -79,7 +79,9 @@ const MyAdsTable = ({ table_ref }) => {
items={my_ads_store.adverts}
keyMapperFn={item => item.id}
loadMoreRowsFn={my_ads_store.loadMoreAds}
- rowRenderer={row_props =>
}
+ rowRenderer={row_props => (
+
+ )}
/>
diff --git a/packages/p2p/src/pages/my-ads/my-ads.jsx b/packages/p2p/src/pages/my-ads/my-ads.jsx
index b84a452ca689..9bc8ec0579f3 100644
--- a/packages/p2p/src/pages/my-ads/my-ads.jsx
+++ b/packages/p2p/src/pages/my-ads/my-ads.jsx
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Loading } from '@deriv/components';
+import { useP2PCountryList } from '@deriv/hooks';
import { observer } from 'mobx-react-lite';
import { localize } from 'Components/i18next';
import { useStores } from 'Stores';
@@ -18,6 +19,7 @@ const MyAdsState = ({ message }) => (
);
const MyAds = () => {
+ const { p2p_country_list = {} } = useP2PCountryList();
const { general_store, my_ads_store, my_profile_store } = useStores();
const is_poi_poa_verified =
general_store.poi_status === identity_status_codes.VERIFIED &&
@@ -53,20 +55,20 @@ const MyAds = () => {
if (my_ads_store.show_ad_form) {
return (
-
+
);
} else if (my_ads_store.show_edit_ad_form) {
return (
-
+
);
}
return (
-
+
);
}
diff --git a/packages/p2p/src/pages/my-ads/preferred-countries-selector/__tests__/preferred-countries-selector.spec.tsx b/packages/p2p/src/pages/my-ads/preferred-countries-selector/__tests__/preferred-countries-selector.spec.tsx
new file mode 100644
index 000000000000..2e46db9e0e19
--- /dev/null
+++ b/packages/p2p/src/pages/my-ads/preferred-countries-selector/__tests__/preferred-countries-selector.spec.tsx
@@ -0,0 +1,116 @@
+import React from 'react';
+import { Formik } from 'formik';
+import { render, screen } from '@testing-library/react';
+import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';
+import PreferredCountriesSelector from '../preferred-countries-selector';
+
+const mock_modal_manager: Partial
> = {
+ showModal: jest.fn(),
+};
+jest.mock('Components/modal-manager/modal-manager-context', () => ({
+ ...jest.requireActual('Components/modal-manager/modal-manager-context'),
+ useModalManagerContext: jest.fn(() => mock_modal_manager),
+}));
+const country_list = {
+ ad: {
+ country_name: 'Andorra',
+ cross_border_ads_enabled: 1,
+ fixed_rate_adverts: 'enabled',
+ float_rate_adverts: 'disabled',
+ float_rate_offset_limit: 10,
+ local_currency: 'EUR',
+ payment_methods: {
+ alipay: {
+ display_name: 'Alipay',
+ fields: {
+ account: {
+ display_name: 'Alipay ID',
+ required: 1,
+ type: 'text',
+ },
+ instructions: {
+ display_name: 'Instructions',
+ required: 0,
+ type: 'memo',
+ },
+ },
+ type: 'ewallet',
+ },
+ },
+ },
+ af: {
+ country_name: 'Afghanistan',
+ cross_border_ads_enabled: 1,
+ fixed_rate_adverts: 'enabled',
+ float_rate_adverts: 'disabled',
+ float_rate_offset_limit: 10,
+ local_currency: 'AFN',
+ payment_methods: {
+ alipay: {
+ display_name: 'Alipay',
+ fields: {
+ account: {
+ display_name: 'Alipay ID',
+ required: 1,
+ type: 'text',
+ },
+ instructions: {
+ display_name: 'Instructions',
+ required: 0,
+ type: 'memo',
+ },
+ },
+ type: 'ewallet',
+ },
+ },
+ },
+ ai: {
+ country_name: 'Anguilla',
+ cross_border_ads_enabled: 1,
+ fixed_rate_adverts: 'enabled',
+ float_rate_adverts: 'disabled',
+ float_rate_offset_limit: 10,
+ local_currency: 'XCD',
+ payment_methods: {
+ alipay: {
+ display_name: 'Alipay',
+ fields: {
+ account: {
+ display_name: 'Alipay ID',
+ required: 1,
+ type: 'text',
+ },
+ instructions: {
+ display_name: 'Instructions',
+ required: 0,
+ type: 'memo',
+ },
+ },
+ type: 'ewallet',
+ },
+ },
+ },
+};
+
+describe('', () => {
+ it('should render the component', () => {
+ render(
+
+
+
+ );
+
+ const selector = screen.getByRole('textbox');
+ expect(selector).toHaveValue('');
+ });
+ it('should render the eligible countries', () => {
+ render(
+
+
+
+ );
+
+ const selector = screen.getByRole('textbox');
+ expect(selector).toHaveValue('Andorra, Afghanistan');
+ });
+});
diff --git a/packages/p2p/src/pages/my-ads/preferred-countries-selector/index.ts b/packages/p2p/src/pages/my-ads/preferred-countries-selector/index.ts
new file mode 100644
index 000000000000..904cdbcb06a7
--- /dev/null
+++ b/packages/p2p/src/pages/my-ads/preferred-countries-selector/index.ts
@@ -0,0 +1,4 @@
+import PreferredCountriesSelector from './preferred-countries-selector';
+import './preferred-countries-selector.scss';
+
+export default PreferredCountriesSelector;
diff --git a/packages/p2p/src/pages/my-ads/preferred-countries-selector/preferred-countries-selector.scss b/packages/p2p/src/pages/my-ads/preferred-countries-selector/preferred-countries-selector.scss
new file mode 100644
index 000000000000..ed7a3413aeec
--- /dev/null
+++ b/packages/p2p/src/pages/my-ads/preferred-countries-selector/preferred-countries-selector.scss
@@ -0,0 +1,14 @@
+.preferred-countries-selector {
+ @include desktop {
+ max-width: 32.8rem !important;
+
+ &__input,
+ &__icon {
+ cursor: pointer;
+ }
+ }
+
+ &__input {
+ text-overflow: ellipsis;
+ }
+}
diff --git a/packages/p2p/src/pages/my-ads/preferred-countries-selector/preferred-countries-selector.tsx b/packages/p2p/src/pages/my-ads/preferred-countries-selector/preferred-countries-selector.tsx
new file mode 100644
index 000000000000..603cd6a614ec
--- /dev/null
+++ b/packages/p2p/src/pages/my-ads/preferred-countries-selector/preferred-countries-selector.tsx
@@ -0,0 +1,72 @@
+import React from 'react';
+import { Field, FormikHelpers, FormikValues, useFormikContext } from 'formik';
+import { Icon, Input } from '@deriv/components';
+import { localize } from 'Components/i18next';
+import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';
+import { TCountryListProps } from 'Types';
+
+type TFormikContext = {
+ setFieldValue?: FormikHelpers['setFieldValue'];
+ values: FormikValues;
+};
+type TPreferredCountriesSelectorProps = {
+ country_list: TCountryListProps;
+};
+
+const PreferredCountriesSelector = ({ country_list }: TPreferredCountriesSelectorProps) => {
+ const { setFieldValue, values }: TFormikContext = useFormikContext();
+ const { showModal } = useModalManagerContext();
+ const countries = Object.keys(country_list).map(key => ({
+ text: country_list[key]?.country_name,
+ value: key,
+ }));
+
+ const getSelectedCountriesText = () => {
+ const eligible_countries = values.eligible_countries;
+ if (eligible_countries?.length === countries.length) {
+ return '';
+ }
+
+ return eligible_countries?.map((value: string) => country_list[value]?.country_name).join(', ');
+ };
+
+ const onClick = () => {
+ showModal({
+ key: 'PreferredCountriesModal',
+ props: {
+ country_list: countries,
+ eligible_countries: values.eligible_countries,
+ onApply: value => {
+ setFieldValue('eligible_countries', [...value]);
+ getSelectedCountriesText();
+ },
+ },
+ });
+ };
+
+ React.useEffect(() => {
+ if (!values.eligible_countries) setFieldValue('eligible_countries', Object.keys(country_list));
+ }, [country_list]);
+
+ return (
+
+ {({ field }: FormikValues) => (
+
+ }
+ type='text'
+ value={getSelectedCountriesText()}
+ />
+ )}
+
+ );
+};
+
+export default PreferredCountriesSelector;
diff --git a/packages/p2p/src/pages/my-ads/sell-ad-payment-methods-list.scss b/packages/p2p/src/pages/my-ads/sell-ad-payment-methods-list.scss
index ca853fa98b3a..9f8152d46660 100644
--- a/packages/p2p/src/pages/my-ads/sell-ad-payment-methods-list.scss
+++ b/packages/p2p/src/pages/my-ads/sell-ad-payment-methods-list.scss
@@ -2,6 +2,7 @@
&__container {
display: grid;
grid-template-columns: repeat(4, 0.19fr);
+ column-gap: 2rem;
&--horizontal {
grid-auto-flow: column;
diff --git a/packages/p2p/src/stores/my-ads-store.js b/packages/p2p/src/stores/my-ads-store.js
index 936055fc8e5a..557b523c7ac0 100644
--- a/packages/p2p/src/stores/my-ads-store.js
+++ b/packages/p2p/src/stores/my-ads-store.js
@@ -21,8 +21,9 @@ export default class MyAdsStore extends BaseStore {
edit_ad_form_error = '';
error_message = '';
has_more_items_to_load = false;
+ min_join_days = 0;
+ min_completion_rate = 0;
is_ad_created_modal_visible = false;
- is_edit_ad_error_modal_visible = false;
is_form_loading = false;
is_table_loading = false;
is_loading = false;
@@ -35,9 +36,9 @@ export default class MyAdsStore extends BaseStore {
table_height = 0;
required_ad_type;
error_code = '';
-
payment_method_ids = [];
payment_method_names = [];
+ preferred_countries = [];
constructor(root_store) {
// TODO: [mobx-undecorate] verify the constructor arguments and the arguments of this automatically generated super call
@@ -55,7 +56,6 @@ export default class MyAdsStore extends BaseStore {
error_message: observable,
has_more_items_to_load: observable,
is_ad_created_modal_visible: observable,
- is_edit_ad_error_modal_visible: observable,
is_form_loading: observable,
is_table_loading: observable,
is_loading: observable,
@@ -95,11 +95,13 @@ export default class MyAdsStore extends BaseStore {
setErrorMessage: action.bound,
setHasMoreItemsToLoad: action.bound,
setIsAdCreatedModalVisible: action.bound,
- setIsEditAdErrorModalVisible: action.bound,
setIsFormLoading: action.bound,
setIsLoading: action.bound,
setIsTableLoading: action.bound,
+ setMinJoinDays: action.bound,
+ setMinCompletionRate: action.bound,
setP2pAdvertInformation: action.bound,
+ setPreferredCountries: action.bound,
setSelectedAdId: action.bound,
setShouldCopyAdvert: action.bound,
setShouldShowAddPaymentMethod: action.bound,
@@ -173,12 +175,15 @@ export default class MyAdsStore extends BaseStore {
const create_advert = {
p2p_advert_create: 1,
type: values.type,
+ eligible_countries: values.eligible_countries,
amount: Number(values.offer_amount),
max_order_amount: Number(values.max_transaction),
min_order_amount: Number(values.min_transaction),
order_expiry_period: values.order_completion_time,
rate_type: values.rate_type_string,
rate: Number(values.rate_type),
+ ...(this.min_completion_rate ? { min_completion_rate: Number(this.min_completion_rate) } : {}),
+ ...(this.min_join_days ? { min_join_days: Number(this.min_join_days) } : {}),
...(this.payment_method_names.length > 0 && !is_sell_ad
? { payment_method_names: this.payment_method_names }
: {}),
@@ -201,7 +206,6 @@ export default class MyAdsStore extends BaseStore {
if (response.error) {
this.setApiErrorCode(response.error.code);
this.setApiErrorMessage(response.error.message);
- this.root_store.general_store.showModal({ key: 'AdCreateEditErrorModal' });
setSubmitting(false);
} else if (should_not_show_auto_archive_message !== 'true') {
this.setAdvertDetails(response.p2p_advert_create);
@@ -211,6 +215,7 @@ export default class MyAdsStore extends BaseStore {
props: { adverts_archive_period },
});
this.setAdFormValues(null);
+ this.setShouldCopyAdvert(false);
} else if (!this.is_ad_created_modal_visible) {
if (!response.p2p_advert_create.is_visible) {
this.setAdvertDetails(response.p2p_advert_create);
@@ -231,6 +236,7 @@ export default class MyAdsStore extends BaseStore {
this.root_store.general_store.hideModal();
this.setShowAdForm(false);
this.setAdFormValues(null);
+ this.setShouldCopyAdvert(false);
}
if (should_reload_ads) this.loadMoreAds({ startIndex: 0 });
@@ -271,14 +277,14 @@ export default class MyAdsStore extends BaseStore {
}
}
- async onClickCopy(id, is_copy_advert_modal_visible) {
+ async onClickCopy(country_list, id, is_copy_advert_modal_visible) {
this.setSelectedAdId(id);
if (is_copy_advert_modal_visible) {
await this.getAdvertInfo();
this.root_store.general_store.showModal({
key: 'CopyAdvertModal',
- props: { advert: this.p2p_advert_information },
+ props: { advert: this.p2p_advert_information, country_list },
});
} else {
this.getAdvertInfo();
@@ -333,11 +339,14 @@ export default class MyAdsStore extends BaseStore {
const update_advert = {
p2p_advert_update: 1,
id: this.selected_ad_id,
+ eligible_countries: values.eligible_countries,
max_order_amount: Number(values.max_transaction),
min_order_amount: Number(values.min_transaction),
order_expiry_period: values.order_completion_time,
rate_type: this.required_ad_type,
rate: Number(values.rate_type),
+ min_completion_rate: Number(this.min_completion_rate) > 0 ? Number(this.min_completion_rate) : null,
+ min_join_days: Number(this.min_join_days) > 0 ? Number(this.min_join_days) : null,
...(this.payment_method_names.length > 0 && !is_sell_ad
? { payment_method_names: this.payment_method_names }
: {}),
@@ -350,8 +359,8 @@ export default class MyAdsStore extends BaseStore {
update_advert.contact_info = values.contact_info;
}
- if (values.description) {
- update_advert.description = values.description;
+ if (values.default_advert_description) {
+ update_advert.description = values.default_advert_description;
}
if (values.reached_target_date) {
update_advert.is_active = values.is_active;
@@ -364,7 +373,6 @@ export default class MyAdsStore extends BaseStore {
setSubmitting(false);
this.setApiErrorCode(response.error.code);
this.setEditAdFormError(response.error.message);
- this.setIsEditAdErrorModalVisible(true);
} else {
this.setShowEditAdForm(false);
}
@@ -511,10 +519,6 @@ export default class MyAdsStore extends BaseStore {
this.should_copy_advert = should_copy_advert;
}
- setIsEditAdErrorModalVisible(is_edit_ad_error_modal_visible) {
- this.is_edit_ad_error_modal_visible = is_edit_ad_error_modal_visible;
- }
-
setIsFormLoading(is_form_loading) {
this.is_form_loading = is_form_loading;
}
@@ -527,10 +531,22 @@ export default class MyAdsStore extends BaseStore {
this.is_table_loading = is_table_loading;
}
+ setMinJoinDays(min_join_days) {
+ this.min_join_days = min_join_days;
+ }
+
+ setMinCompletionRate(min_completion_rate) {
+ this.min_completion_rate = min_completion_rate;
+ }
+
setP2pAdvertInformation(p2p_advert_information) {
this.p2p_advert_information = p2p_advert_information;
}
+ setPreferredCountries(preferred_countries) {
+ this.preferred_countries = preferred_countries;
+ }
+
setSelectedAdId(selected_ad_id) {
this.selected_ad_id = selected_ad_id;
}
diff --git a/packages/p2p/src/types/adverts.types.ts b/packages/p2p/src/types/adverts.types.ts
index 2523865af119..27b177383a40 100644
--- a/packages/p2p/src/types/adverts.types.ts
+++ b/packages/p2p/src/types/adverts.types.ts
@@ -29,8 +29,10 @@ export type TAdvertProps = {
description: string;
effective_rate: number;
effective_rate_display: string;
+ eligibility_status: string[];
id: string;
is_active: number;
+ is_eligible: number;
is_visible: number;
local_currency: string;
max_order_amount: number;
@@ -56,3 +58,7 @@ export type TAdvertProps = {
type: string;
visibility_status: string[];
};
+
+export type TCountryListProps = {
+ [key: string]: { country_name: string };
+};
diff --git a/packages/p2p/src/utils/__tests__/adverts.spec.ts b/packages/p2p/src/utils/__tests__/adverts.spec.ts
index 13005daa91ef..301e599e509c 100644
--- a/packages/p2p/src/utils/__tests__/adverts.spec.ts
+++ b/packages/p2p/src/utils/__tests__/adverts.spec.ts
@@ -1,6 +1,11 @@
import moment from 'moment';
import { toMoment } from '@deriv/shared';
-import { generateErrorDialogBody, generateErrorDialogTitle, getLastOnlineLabel } from '../adverts';
+import {
+ generateErrorDialogBody,
+ generateErrorDialogTitle,
+ getEligibilityMessage,
+ getLastOnlineLabel,
+} from '../adverts';
let mock_value: moment.Moment = moment();
jest.mock('@deriv/shared', () => ({
@@ -104,3 +109,17 @@ describe('getLastOnlineLabel', () => {
expect(getLastOnlineLabel(is_online)).toBe('Seen more than 6 months ago');
});
});
+
+describe('getEligibilityMessage', () => {
+ it('should return "Your completion rate is too low for this ad." if eligibility statuses only contains completion_rate', () => {
+ expect(getEligibilityMessage(['completion_rate'])).toBe('Your completion rate is too low for this ad.');
+ });
+ it('should return "You\'ve not used Deriv P2P long enough for this ad." if eligibility statuses only contains join_date', () => {
+ expect(getEligibilityMessage(['join_date'])).toBe("You've not used Deriv P2P long enough for this ad.");
+ });
+ it('should return "The advertiser has set conditions for this ad that you don\'t meet." if eligibility statuses contains more than one reason', () => {
+ expect(getEligibilityMessage(['completion_rate, join_date'])).toBe(
+ "The advertiser has set conditions for this ad that you don't meet."
+ );
+ });
+});
diff --git a/packages/p2p/src/utils/adverts.ts b/packages/p2p/src/utils/adverts.ts
index 264be85f716e..e7ce500fc00a 100644
--- a/packages/p2p/src/utils/adverts.ts
+++ b/packages/p2p/src/utils/adverts.ts
@@ -114,3 +114,21 @@ export const getLastOnlineLabel = (is_online: 0 | 1, last_online_time?: number)
}
return localize('Online');
};
+
+/**
+ * Function to get the message to be shown to users when they are not eligible to create an order against an advert.
+ *
+ * @param {string[]} eligibility_statuses - The list of reasons why the user is not eligible.
+ * @returns {string} The eligibility message based on the given eligibility statuses.
+ */
+export const getEligibilityMessage = (eligibility_statuses: string[]) => {
+ if (eligibility_statuses.length === 1) {
+ if (eligibility_statuses.includes('completion_rate')) {
+ return localize('Your completion rate is too low for this ad.');
+ } else if (eligibility_statuses.includes('join_date')) {
+ return localize("You've not used Deriv P2P long enough for this ad.");
+ }
+ }
+
+ return localize("The advertiser has set conditions for this ad that you don't meet.");
+};