Skip to content

Commit

Permalink
Merge pull request #47 from farabi-deriv/farabi/bot-1859/fix--quick-s…
Browse files Browse the repository at this point in the history
…trategy-flow-and-functions

Farabi/bot-1859/fix--quick-strategy-flow-and-functions
  • Loading branch information
sandeep-deriv authored Sep 4, 2024
2 parents e0b9649 + 63334cc commit 385f86f
Show file tree
Hide file tree
Showing 29 changed files with 222 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/components/shared_ui/input/input.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import classNames from 'classnames';
import { Text } from '@deriv-com/ui';
import Field from '../field';
import Text from '../text';

export type TInputProps = {
autoComplete?: string;
Expand Down
1 change: 0 additions & 1 deletion src/components/shared_ui/modal/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Modal from './modal';

import './modal.scss';

export default Modal;
2 changes: 1 addition & 1 deletion src/components/shared_ui/select-native/select-native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import classNames from 'classnames';
import { Icon } from '@/utils/tmp/dummy';
import { LabelPairedChevronDownLgRegularIcon } from '@deriv/quill-icons';
import { Text } from '@deriv-com/ui';
import Field from '../field/field';
import Text from '../text';

type TSelectNative = {
className?: string;
Expand Down
4 changes: 4 additions & 0 deletions src/components/shared_ui/toggle-switch/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ToggleSwitch from './toggle-switch';
import './toggle-switch.scss';

export default ToggleSwitch;
35 changes: 35 additions & 0 deletions src/components/shared_ui/toggle-switch/toggle-switch.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.dc-toggle-switch {
height: 0;
width: 0;
visibility: hidden;

&__label {
display: flex;
align-items: center;
margin-left: auto;
margin-right: 1.6rem;
padding-left: 0.4rem;
cursor: pointer;
width: 4.9rem;
height: 2.52rem;
background: var(--general-disabled);
border-radius: 4.9rem;
transition: background-color 0.25s;
}

&__button {
width: 1.9rem;
height: 1.9rem;
border-radius: 1.9rem;
transition: transform 0.25s;
background: var(--text-colored-background);
}

&:checked + &__label {
background: var(--text-profit-success);
}

&:checked + &__label &__button {
transform: translateX(2.25rem);
}
}
40 changes: 40 additions & 0 deletions src/components/shared_ui/toggle-switch/toggle-switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react';
import classNames from 'classnames';

type TToggleSwitch = {
className?: string;
classNameButton?: string;
classNameLabel?: string;
handleToggle: () => void;
id: string;
is_enabled: boolean;
name?: string;
};

const ToggleSwitch = ({
className,
classNameButton,
classNameLabel,
handleToggle,
id,
is_enabled,
name = 'toggle_switch',
}: TToggleSwitch) => {
return (
<React.Fragment>
<input
aria-label={name}
className={classNames('dc-toggle-switch', className)}
id={id}
type='checkbox'
checked={is_enabled}
onChange={handleToggle}
/>
<label className={classNames('dc-toggle-switch__label', classNameLabel)} htmlFor={id}>
<span className={classNames('dc-toggle-switch__button', classNameButton)} />
</label>
</React.Fragment>
);
};

export default ToggleSwitch;
2 changes: 1 addition & 1 deletion src/pages/bot-builder/quick-strategy/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config as qs_config } from '@/external/bot-skeleton';
import { localize } from '@deriv-com/translations';
import { localize } from '@/utils/tmp/dummy';
import {
D_ALEMBERT,
MARTINGALE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames';
import { observer } from 'mobx-react-lite';
import Text from '@/components/shared_ui/text';
import { useStore } from '@/hooks/useStore';
import { Text } from '@deriv-com/ui';
import { TStrategyDescription } from '../types';

const StrategyDescription = observer(({ item, font_size }: TStrategyDescription) => {
Expand Down Expand Up @@ -37,7 +37,7 @@ const StrategyDescription = observer(({ item, font_size }: TStrategyDescription)
const class_names = classNames(`qs__description__image ${class_name}`);
return (
<div className={class_names} style={item?.styles}>
<img src={is_dark_mode_on ? item.dark_src ?? item.src : item.src} alt={item.alt} />
<img src={is_dark_mode_on ? (item.dark_src ?? item.src) : item.src} alt={item.alt} />
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React from 'react';
import classNames from 'classnames';
import { useFormikContext } from 'formik';
import { observer } from 'mobx-react-lite';
import Button from '@/components/shared_ui/button';
import Text from '@/components/shared_ui/text';
import ThemedScrollbars from '@/components/shared_ui/themed-scrollbars';
import { useStore } from '@/hooks/useStore';
import { LegacyClose1pxIcon } from '@deriv/quill-icons';
import { Localize } from '@deriv-com/translations';
import { Button, Text } from '@deriv-com/ui';
import {
rudderStackSendQsEditStrategyEvent,
rudderStackSendQsRunStrategyEvent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { KeyboardEvent } from 'react';
import classNames from 'classnames';
import { observer } from 'mobx-react-lite';
import { Text } from '@deriv-com/ui';
import Text from '@/components/shared_ui/text';
import { FORM_TABS } from '../config';
import { TDescriptionItem } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SelectNative from '@/components/shared_ui/select-native';
import Text from '@/components/shared_ui/text';
import ThemedScrollbars from '@/components/shared_ui/themed-scrollbars';
import { useStore } from '@/hooks/useStore';
import { localize } from '@/utils/tmp/dummy';
import { localize } from '@deriv-com/translations';
import {
rudderStackSendQsRunStrategyEvent,
rudderStackSendQsSelectedTabEvent,
Expand Down
31 changes: 23 additions & 8 deletions src/pages/bot-builder/quick-strategy/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ const QuickStrategyForm = observer(() => {
const { quick_strategy } = useStore();
const { selected_strategy, setValue, form_data } = quick_strategy;
const config: TConfigItem[][] = STRATEGIES[selected_strategy]?.fields;
const { is_mobile } = ui;
const { is_desktop } = ui;
const { values, setFieldTouched, setFieldValue } = useFormikContext<TFormData>();
const { current_duration_min_max, is_enabled_toggle_switch, setIsEnabledToggleSwitch } = quick_strategy;
const { current_duration_min_max } = quick_strategy;

const [isEnabledToggleSwitch, setIsEnabledToggleSwitch] = React.useState(false);

React.useEffect(() => {
window.addEventListener('keydown', handleEnter);
let data: TFormData | null = null;
try {
data = JSON.parse(localStorage.getItem('qs-fields') ?? '{}');
} catch {
data = null;
}
setIsEnabledToggleSwitch(!!data?.boolean_max_stake);

return () => {
window.removeEventListener('keydown', handleEnter);
};
Expand All @@ -50,6 +61,10 @@ const QuickStrategyForm = observer(() => {
return values[item.key as keyof TFormData] === item.value;
});

const toggleSwitch = () => {
setIsEnabledToggleSwitch(prev => !prev);
};

const renderForm = () => {
return config.map((group, group_index) => {
if (!group?.length) return null;
Expand All @@ -59,8 +74,8 @@ const QuickStrategyForm = observer(() => {
const key = `${field.name || field.type} + ${field_index}`;

if (
(is_mobile && field.hide?.includes('mobile')) ||
(!is_mobile && field.hide?.includes('desktop'))
(!is_desktop && field.hide?.includes('mobile')) ||
(is_desktop && field.hide?.includes('desktop'))
) {
return null;
}
Expand All @@ -84,7 +99,7 @@ const QuickStrategyForm = observer(() => {
}
const should_validate = field.should_have;
if (should_validate && field.name === 'max_stake') {
min = +(form_data?.stake ?? 0);
min = +form_data?.stake;
if (isNaN(min)) {
min = +initial_stake;
}
Expand All @@ -102,7 +117,7 @@ const QuickStrategyForm = observer(() => {
max = 9;
}
if (should_have?.length) {
if (!should_enable && (is_mobile || hide_without_should_have)) {
if (!should_enable && (!is_desktop || hide_without_should_have)) {
return null;
}
return (
Expand Down Expand Up @@ -148,8 +163,8 @@ const QuickStrategyForm = observer(() => {
key={key}
name={field.name as string}
label={field.label as string}
isEnabledToggleSwitch={!!is_enabled_toggle_switch}
setIsEnabledToggleSwitch={setIsEnabledToggleSwitch}
isEnabledToggleSwitch={!!isEnabledToggleSwitch}
setIsEnabledToggleSwitch={toggleSwitch}
/>
);
// Dedicated components only for Quick-Strategy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Popover from '@/components/shared_ui/popover';
import { Text } from '@deriv-com/ui';
import Text from '@/components/shared_ui/text';

type TQSInputLabel = {
children?: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/bot-builder/quick-strategy/inputs/qs-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React, { MouseEvent } from 'react';
import classNames from 'classnames';
import { Field, FieldProps, useFormikContext } from 'formik';
import { observer } from 'mobx-react-lite';
import Input from '@/components/shared_ui/input';
import Popover from '@/components/shared_ui/popover';
import { useStore } from '@/hooks/useStore';
import { Input } from '@deriv-com/ui';

type TQSInput = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from 'react';
import classNames from 'classnames';
import { Field, useFormikContext } from 'formik';
import Popover from '@/components/shared_ui/popover';
import { localize } from '@/utils/tmp/dummy';
import { Text, ToggleSwitch } from '@deriv-com/ui';
import Text from '@/components/shared_ui/text';
import ToggleSwitch from '@/components/shared_ui/toggle-switch';
import { localize } from '@deriv-com/translations';
import { TFormData } from '../types';

type TQSToggleSwitch = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { observer } from 'mobx-react-lite';
import Checkbox from '@/components/shared_ui/checkbox';
import Dialog from '@/components/shared_ui/dialog';
import { useStore } from '@/hooks/useStore';
import { Localize, localize } from '@/utils/tmp/dummy';
import { Checkbox, Dialog } from '@deriv-com/ui';
import { Localize, localize } from '@deriv-com/translations';
import useQsSubmitHandler from '../form-wrappers/useQsSubmitHandler';
import './loss-threshold-warning-dialog.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/bot-builder/quick-strategy/quick-strategy.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
@include flex-center(space-between);

border-bottom: 1px solid var(--border-divider);
background-color: var(--general-section-1);

&__title {
@extend .x-center;

padding: 0 2.4rem;
height: var(--header-height);
background-color: var(--general-section-1);
width: var(--sidebar-width);
}

Expand Down
Loading

0 comments on commit 385f86f

Please sign in to comment.