From 9162bd0c0e085df358252e6ddb7e7e97a78e290b Mon Sep 17 00:00:00 2001 From: Gregory <117281520+gca-axelor@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:03:29 +0100 Subject: [PATCH] feat: restore ControlEntryDetailsScreen --- .../ControlEntryDetailsHeader.tsx | 49 ++++- .../ControlEntryHeader/ControlEntryHeader.tsx | 180 ------------------ .../quality/src/components/molecules/index.js | 1 - .../src/screens/ControlEntryDetailsScreen.js | 1 - 4 files changed, 48 insertions(+), 183 deletions(-) delete mode 100644 packages/apps/quality/src/components/molecules/ControlEntryHeader/ControlEntryHeader.tsx diff --git a/packages/apps/quality/src/components/molecules/ControlEntryDetailsHeader/ControlEntryDetailsHeader.tsx b/packages/apps/quality/src/components/molecules/ControlEntryDetailsHeader/ControlEntryDetailsHeader.tsx index 10e6d2e29a..3556c928c6 100644 --- a/packages/apps/quality/src/components/molecules/ControlEntryDetailsHeader/ControlEntryDetailsHeader.tsx +++ b/packages/apps/quality/src/components/molecules/ControlEntryDetailsHeader/ControlEntryDetailsHeader.tsx @@ -18,11 +18,17 @@ import React, {useEffect, useState} from 'react'; import {StyleSheet, View} from 'react-native'; -import {DateDisplay, useTranslator} from '@axelor/aos-mobile-core'; import { + DateDisplay, + useNavigation, + useTranslator, +} from '@axelor/aos-mobile-core'; +import { + Alert, Badge, Button, ProgressBar, + RadioSelect, Text, useThemeColor, } from '@axelor/aos-mobile-ui'; @@ -46,10 +52,13 @@ const ControlEntryDetailsHeader = ({ controlPlanName, entryDateTime, }: ControlEntryHeaderProps) => { + const navigation = useNavigation(); const I18n = useTranslator(); const Colors = useThemeColor(); const [numberSampleFilled, setNumberSampleFilled] = useState(0); + const [showAlert, setShowAlert] = useState(false); + const [selectedMode, setSelectedMode] = useState(null); useEffect(() => { searchControlEntrySampleApi({controlEntryId: controlEntryId}) @@ -96,8 +105,43 @@ const ControlEntryDetailsHeader = ({ iconName="clipboard2-fill" width="10%" style={styles.button} + onPress={() => setShowAlert(true)} /> + { + setShowAlert(false); + }, + }} + confirmButtonConfig={{ + hide: false, + width: '15%', + styleTxt: {display: 'none'}, + disabled: selectedMode == null, + onPress: () => { + setShowAlert(false); + navigation.navigate('ControlEntryFormScreen', { + controlEntryId: controlEntryId, + selectedMode: selectedMode, + }); + }, + }}> + + ); }; @@ -121,6 +165,9 @@ const styles = StyleSheet.create({ height: 40, borderWidth: 1, }, + radioSelect: { + height: 150, + }, }); export default ControlEntryDetailsHeader; diff --git a/packages/apps/quality/src/components/molecules/ControlEntryHeader/ControlEntryHeader.tsx b/packages/apps/quality/src/components/molecules/ControlEntryHeader/ControlEntryHeader.tsx deleted file mode 100644 index 9e35f5eab6..0000000000 --- a/packages/apps/quality/src/components/molecules/ControlEntryHeader/ControlEntryHeader.tsx +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Axelor Business Solutions - * - * Copyright (C) 2024 Axelor (). - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import React, {useEffect, useState} from 'react'; -import {StyleSheet, View} from 'react-native'; -import { - isEmpty, - useSelector, - useTranslator, - useDispatch, - DateDisplay, - useNavigation, -} from '@axelor/aos-mobile-core'; -import { - Alert, - Badge, - ProgressBar, - RadioSelect, - Text, - ToggleButton, - useThemeColor, -} from '@axelor/aos-mobile-ui'; -import {ControlEntry} from '../../../types'; -import {fetchControlEntryById} from '../../../features/controlEntrySlice'; -import {searchControlEntrySampleApi} from '../../../api'; - -interface ControlEntryHeaderProps { - controlEntryId: number; -} - -const ControlEntryHeader = ({controlEntryId}: ControlEntryHeaderProps) => { - const navigation = useNavigation(); - const I18n = useTranslator(); - const Colors = useThemeColor(); - const dispatch = useDispatch(); - - const {controlEntry} = useSelector((state: any) => state.controlEntry); - - const [showAlert, setShowAlert] = useState(false); - const [numberSampleFilled, setNumberSampleFilled] = useState(0); - const [selectedMode, setSelectedMode] = useState(null); - - useEffect(() => { - dispatch((fetchControlEntryById as any)({controlEntryId: controlEntryId})); - }, [controlEntryId, dispatch]); - - useEffect(() => { - searchControlEntrySampleApi({controlEntryId: controlEntryId}) - .then(response => { - if (Array.isArray(response?.data?.data)) { - const controlEntrySampleList: any[] = response.data.data; - const total = controlEntrySampleList.length; - const notControlled = controlEntrySampleList.filter( - sample => - sample.resultSelect === ControlEntry.sampleResult.NotControlled, - ).length; - - setNumberSampleFilled(100 - (notControlled / total) * 100); - } else { - setNumberSampleFilled(0); - } - }) - .catch(() => setNumberSampleFilled(0)); - }, [controlEntryId]); - - if (controlEntry == null || isEmpty(controlEntry)) { - return null; - } - - return ( - - - {controlEntry.name} - - - - {`${I18n.t('Quality_Sample')} : ${ - controlEntry.sampleCount - }`} - - - {`${I18n.t('Quality_ControlPlan')} : ${ - controlEntry.controlPlan?.name - }`} - - - setShowAlert(true)} - buttonConfig={{ - iconName: 'clipboard2-fill', - width: '10%', - style: styles.toggleButton, - }} - /> - - { - setShowAlert(false); - }, - }} - confirmButtonConfig={{ - hide: false, - width: '15%', - styleTxt: {display: 'none'}, - disabled: selectedMode == null, - onPress: () => { - setShowAlert(false); - navigation.navigate('ControlEntryFormScreen', { - controlEntryId: controlEntryId, - selectedMode: selectedMode, - }); - }, - }}> - - - - ); -}; - -const styles = StyleSheet.create({ - container: { - marginHorizontal: 24, - }, - row: { - justifyContent: 'space-between', - flexDirection: 'row', - marginVertical: 2, - }, - progressHeader: { - justifyContent: 'space-between', - flexDirection: 'row', - marginTop: '3%', - }, - progressBar: { - width: '85%', - }, - toggleButton: { - height: 40, - top: '-20%', - }, - radioSelect: { - height: 150, - }, -}); - -export default ControlEntryHeader; diff --git a/packages/apps/quality/src/components/molecules/index.js b/packages/apps/quality/src/components/molecules/index.js index 6022e7548e..ea7fe4d643 100644 --- a/packages/apps/quality/src/components/molecules/index.js +++ b/packages/apps/quality/src/components/molecules/index.js @@ -20,4 +20,3 @@ export {default as ControlEntryDetailsButtons} from './ControlEntryDetailsButton export {default as ControlEntryDetailsHeader} from './ControlEntryDetailsHeader/ControlEntryDetailsHeader'; export {default as ControlEntryFormButtons} from './ControlEntryFormButtons/ControlEntryFormButtons'; export {default as ControlEntryFormHeader} from './ControlEntryFormHeader/ControlEntryFormHeader'; -export {default as ControlEntryHeader} from './ControlEntryHeader/ControlEntryHeader'; diff --git a/packages/apps/quality/src/screens/ControlEntryDetailsScreen.js b/packages/apps/quality/src/screens/ControlEntryDetailsScreen.js index 6563838c37..653ec5b702 100644 --- a/packages/apps/quality/src/screens/ControlEntryDetailsScreen.js +++ b/packages/apps/quality/src/screens/ControlEntryDetailsScreen.js @@ -32,7 +32,6 @@ const ControlEntryDetailsScreen = ({route}) => { const dispatch = useDispatch(); const I18n = useTranslator(); - const Colors = useThemeColor(); const { controlEntrySampleList,