-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1790 from ever-co/improve/status-value-removal-wh…
…en-selected-one-pressed Improve/status value removal when selected one pressed
- Loading branch information
Showing
4 changed files
with
160 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,124 @@ | ||
/* eslint-disable react-native/no-color-literals */ | ||
/* eslint-disable react-native/no-inline-styles */ | ||
import React, { FC, useState } from 'react'; | ||
import { TouchableOpacity, View, Text, StyleSheet, ViewStyle } from 'react-native'; | ||
import { AntDesign, Entypo } from '@expo/vector-icons'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { ITeamTask } from '../services/interfaces/ITask'; | ||
import { useTeamTasks } from '../services/hooks/features/useTeamTasks'; | ||
import { typography, useAppTheme } from '../theme'; | ||
import TaskPriorityPopup from './TaskPriorityPopup'; | ||
import { translate } from '../i18n'; | ||
import { useTaskPriorityValue } from './StatusType'; | ||
import { limitTextCharaters } from '../helpers/sub-text'; | ||
import React, { FC, useState } from "react" | ||
import { TouchableOpacity, View, Text, StyleSheet, ViewStyle } from "react-native" | ||
import { AntDesign, Entypo } from "@expo/vector-icons" | ||
import { observer } from "mobx-react-lite" | ||
import { ITeamTask } from "../services/interfaces/ITask" | ||
import { useTeamTasks } from "../services/hooks/features/useTeamTasks" | ||
import { typography, useAppTheme } from "../theme" | ||
import TaskPriorityPopup from "./TaskPriorityPopup" | ||
import { translate } from "../i18n" | ||
import { useTaskPriorityValue } from "./StatusType" | ||
import { limitTextCharaters } from "../helpers/sub-text" | ||
|
||
interface TaskPriorityProps { | ||
task?: ITeamTask; | ||
containerStyle?: ViewStyle; | ||
priority?: string; | ||
setPriority?: (priority: string) => unknown; | ||
task?: ITeamTask | ||
containerStyle?: ViewStyle | ||
priority?: string | ||
setPriority?: (priority: string) => unknown | ||
} | ||
|
||
const TaskPriority: FC<TaskPriorityProps> = observer(({ task, containerStyle, priority, setPriority }) => { | ||
const { colors } = useAppTheme(); | ||
const { updateTask } = useTeamTasks(); | ||
const [openModal, setOpenModal] = useState(false); | ||
const TaskPriority: FC<TaskPriorityProps> = observer( | ||
({ task, containerStyle, priority, setPriority }) => { | ||
const { colors } = useAppTheme() | ||
const { updateTask } = useTeamTasks() | ||
const [openModal, setOpenModal] = useState(false) | ||
|
||
const allTaskPriorities = useTaskPriorityValue(); | ||
const allTaskPriorities = useTaskPriorityValue() | ||
|
||
const sizeValue = ( | ||
task?.priority?.split('-').join(' ') || | ||
(priority && priority.split('-').join(' ')) | ||
)?.toLowerCase(); | ||
const sizeValue = ( | ||
task?.priority?.split("-").join(" ") || | ||
(priority && priority.split("-").join(" ")) | ||
)?.toLowerCase() | ||
|
||
const currentPriority = | ||
allTaskPriorities && Object.values(allTaskPriorities).find((item) => item.name.toLowerCase() === sizeValue); | ||
const currentPriority = | ||
allTaskPriorities && | ||
Object.values(allTaskPriorities).find((item) => item.name.toLowerCase() === sizeValue) | ||
|
||
const onChangePriority = async (text) => { | ||
if (task) { | ||
const taskEdit = { | ||
...task, | ||
priority: text | ||
}; | ||
const onChangePriority = async (text: string) => { | ||
if (task) { | ||
const taskEdit = { | ||
...task, | ||
priority: task?.priority === text ? null : text, | ||
} | ||
|
||
await updateTask(taskEdit, task.id); | ||
} else { | ||
setPriority(text); | ||
await updateTask(taskEdit, task.id) | ||
} else { | ||
setPriority(text) | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<TaskPriorityPopup | ||
priorityName={task ? task?.priority : priority} | ||
visible={openModal} | ||
setSelectedPriority={(e) => onChangePriority(e.value)} | ||
onDismiss={() => setOpenModal(false)} | ||
/> | ||
<TouchableOpacity onPress={() => setOpenModal(true)}> | ||
<View | ||
style={{ | ||
...styles.container, | ||
...containerStyle, | ||
borderColor: colors.border, | ||
backgroundColor: currentPriority?.bgColor | ||
}} | ||
> | ||
{(task?.priority || priority) && currentPriority ? ( | ||
<View style={styles.wrapStatus}> | ||
{currentPriority.icon} | ||
<Text style={{ ...styles.text, marginLeft: 10 }}> | ||
{limitTextCharaters({ text: currentPriority.name, numChars: 15 })} | ||
</Text> | ||
</View> | ||
) : ( | ||
<View style={styles.wrapStatus}> | ||
<Entypo name="circle" size={12} color={colors.primary} /> | ||
<Text style={{ ...styles.text, color: colors.primary, marginLeft: 5 }}> | ||
{translate('settingScreen.priorityScreen.priorities')} | ||
</Text> | ||
</View> | ||
)} | ||
<AntDesign name="down" size={14} color={task?.priority || priority ? '#000000' : colors.primary} /> | ||
</View> | ||
</TouchableOpacity> | ||
</> | ||
); | ||
}); | ||
return ( | ||
<> | ||
<TaskPriorityPopup | ||
priorityName={task ? task?.priority : priority} | ||
visible={openModal} | ||
setSelectedPriority={(e) => onChangePriority(e.value)} | ||
onDismiss={() => setOpenModal(false)} | ||
/> | ||
<TouchableOpacity onPress={() => setOpenModal(true)}> | ||
<View | ||
style={{ | ||
...styles.container, | ||
...containerStyle, | ||
borderColor: colors.border, | ||
backgroundColor: currentPriority?.bgColor, | ||
}} | ||
> | ||
{(task?.priority || priority) && currentPriority ? ( | ||
<View style={styles.wrapStatus}> | ||
{currentPriority.icon} | ||
<Text style={{ ...styles.text, marginLeft: 10 }}> | ||
{limitTextCharaters({ | ||
text: currentPriority.name, | ||
numChars: 15, | ||
})} | ||
</Text> | ||
</View> | ||
) : ( | ||
<View style={styles.wrapStatus}> | ||
<Entypo name="circle" size={12} color={colors.primary} /> | ||
<Text | ||
style={{ ...styles.text, color: colors.primary, marginLeft: 5 }} | ||
> | ||
{translate("settingScreen.priorityScreen.priorities")} | ||
</Text> | ||
</View> | ||
)} | ||
<AntDesign | ||
name="down" | ||
size={14} | ||
color={task?.priority || priority ? "#000000" : colors.primary} | ||
/> | ||
</View> | ||
</TouchableOpacity> | ||
</> | ||
) | ||
}, | ||
) | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
alignItems: 'center', | ||
borderColor: 'rgba(0,0,0,0.16)', | ||
alignItems: "center", | ||
borderColor: "rgba(0,0,0,0.16)", | ||
borderRadius: 10, | ||
borderWidth: 1, | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
flexDirection: "row", | ||
justifyContent: "space-between", | ||
minHeight: 30, | ||
minWidth: 100, | ||
paddingHorizontal: 8 | ||
paddingHorizontal: 8, | ||
}, | ||
text: { | ||
fontFamily: typography.fonts.PlusJakartaSans.semiBold, | ||
fontSize: 10 | ||
fontSize: 10, | ||
}, | ||
wrapStatus: { | ||
alignItems: 'center', | ||
flexDirection: 'row', | ||
width: '70%' | ||
} | ||
}); | ||
alignItems: "center", | ||
flexDirection: "row", | ||
width: "70%", | ||
}, | ||
}) | ||
|
||
export default TaskPriority; | ||
export default TaskPriority |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.