Skip to content

Commit

Permalink
refactor: remove condition on input
Browse files Browse the repository at this point in the history
  • Loading branch information
gca-axelor committed Jan 9, 2025
1 parent 900628a commit 4dd02e5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react';
import React, {useMemo} from 'react';
import {useTranslator} from '@axelor/aos-mobile-core';
import {QuantityCard, Text} from '@axelor/aos-mobile-ui';
import {checkNullString, QuantityCard, Text} from '@axelor/aos-mobile-ui';

interface RequestCreationQuantityCardProps {
quantity: number;
Expand All @@ -36,18 +36,23 @@ const RequestCreationQuantityCard = ({
}: RequestCreationQuantityCardProps) => {
const I18n = useTranslator();

const isProductName = useMemo(
() => !checkNullString(productName),
[productName],
);

return (
<QuantityCard
labelQty={I18n.t('Purchase_Quantity')}
defaultValue={quantity}
onValueChange={setQuantity}
editable={true}
actionQty={true}
actionQty={isProductName}
iconName="x-lg"
onPressActionQty={cancelMove}
isBigButton={true}
translator={I18n.t}>
<Text fontSize={16}>{productName}</Text>
{isProductName && <Text fontSize={16}>{productName}</Text>}
</QuantityCard>
);
};
Expand Down
76 changes: 32 additions & 44 deletions packages/apps/purchase/src/screens/RequestCreationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const RequestCreationScreen = () => {
handleReset(RequestCreation.step.addLine);
} else {
setNewLine(_value);
setProductTitle(_value.name);
setUnit(_value?.unit);
setIsCustomProduct(false);
setCurrentStep(RequestCreation.step.validateLine);
}
},
Expand Down Expand Up @@ -144,49 +146,35 @@ const RequestCreationScreen = () => {
handleEditLine={handleEditLine}
translator={I18n.t}
/>
{currentStep === RequestCreation.step.addLine && !isCustomProduct && (
<ProductSearchBar
onChange={handleProductChange}
defaultValue={newLine}
isScrollViewContainer
/>
)}
{currentStep < RequestCreation.step.validateLine && (
<HorizontalRuleText
text={I18n.t('Purchase_Or')}
style={styles.rule}
/>
)}
{(currentStep === RequestCreation.step.addLine ||
(RequestCreation.step.validateLine && isCustomProduct)) && (
<FormInput
title={I18n.t('Purchase_ProductTitle')}
defaultValue={productTitle}
onChange={value => {
handleCustomProductInput(value);
if (value) {
setCurrentStep(RequestCreation.step.validateLine);
}
}}
/>
)}
{currentStep === RequestCreation.step.validateLine && (
<>
<RequestCreationQuantityCard
quantity={quantity}
setQuantity={setQuantity}
cancelMove={() => handleReset(RequestCreation.step.addLine)}
productName={newLine?.name || productTitle}
productUnit={unit?.name || newLine?.product?.unit?.name}
/>
<UnitSearchBar
defaultValue={unit}
onChange={setUnit}
isScrollViewContainer={true}
required={true}
/>
</>
)}
<ProductSearchBar
onChange={handleProductChange}
defaultValue={newLine}
/>
<HorizontalRuleText text={I18n.t('Purchase_Or')} style={styles.rule} />
<FormInput
readOnly={!isCustomProduct && newLine?.name != null}
title={I18n.t('Purchase_ProductTitle')}
defaultValue={isCustomProduct ? productTitle : newLine?.name}
onChange={value => {
handleCustomProductInput(value);
if (value) {
setCurrentStep(RequestCreation.step.validateLine);
}
}}
/>
<RequestCreationQuantityCard
quantity={quantity}
setQuantity={setQuantity}
cancelMove={() => handleReset(RequestCreation.step.addLine)}
productName={newLine?.name || productTitle}
productUnit={unit?.name || newLine?.product?.unit?.name}
/>
<UnitSearchBar
defaultValue={unit}
onChange={setUnit}
required={true}
isScrollViewContainer={true}
/>
</KeyboardAvoidingScrollView>
</Screen>
);
Expand All @@ -198,7 +186,7 @@ const styles = StyleSheet.create({
paddingTop: 10,
},
rule: {
marginVertical: 15,
marginTop: 5,
width: '80%',
},
});
Expand Down

0 comments on commit 4dd02e5

Please sign in to comment.