Skip to content

Commit

Permalink
Code improvements and adjustments [skip-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi749 committed Nov 13, 2024
1 parent 7687ed9 commit 5cfa41c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import { useIdeaModuleContext } from '../context'
export function useIdeaField(props: IIdeaFieldProps) {
const context = useIdeaModuleContext()

const isInProcessing = context.state.selectedIdea.item.processing

const renderValueForField = () => {
let icon = TagMultipleFilled

Expand Down Expand Up @@ -156,32 +154,42 @@ export function useIdeaField(props: IIdeaFieldProps) {
const processing = context.state.configuration.processing
const registration = context.state.configuration.registration

const approveValue = isInProcessing
? processing.find((p) => p.key === 'approve')?.recommendation
: registration.find((p) => p.key === 'approve')?.recommendation
const considerationValue = isInProcessing
? processing.find((p) => p.key === 'consideration')?.recommendation
: registration.find((p) => p.key === 'consideration')?.recommendation
const rejectValue = isInProcessing
? processing.find((p) => p.key === 'reject')?.recommendation
: registration.find((p) => p.key === 'reject')?.recommendation
const approveValue = [
processing.find((p) => p.key === 'approve')?.recommendation,
registration.find((p) => p.key === 'approve')?.recommendation
]
const considerationValue = [
processing.find((p) => p.key === 'consideration')?.recommendation,
registration.find((p) => p.key === 'consideration')?.recommendation
]
const rejectValue = [
processing.find((p) => p.key === 'reject')?.recommendation,
registration.find((p) => p.key === 'reject')?.recommendation
]

const statusStyles = {
[approveValue]: {
approve: {
backgroundColor: 'var(--colorPaletteLightGreenBackground2)',
icon: getFluentIcon('CheckmarkCircle')
},
[considerationValue]: {
consideration: {
backgroundColor: 'var(--colorPaletteYellowBackground2)',
icon: getFluentIcon('Edit')
},
[rejectValue]: {
reject: {
backgroundColor: 'var(--colorPaletteRedBackground2)',
icon: getFluentIcon('DismissCircle')
}
}

const { backgroundColor, icon } = statusStyles[textValue] || {
const statusKey = ['approve', 'consideration', 'reject'].find(
(key) =>
approveValue.includes(textValue) ||
considerationValue.includes(textValue) ||
rejectValue.includes(textValue)
)

const { backgroundColor, icon } = statusStyles[statusKey] || {
backgroundColor: 'var(--colorNeutralBackground2)',
icon: null
}
Expand Down Expand Up @@ -215,5 +223,5 @@ export function useIdeaField(props: IIdeaFieldProps) {
}
}

return { renderValueForField, isInProcessing }
return { renderValueForField }
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const IdeaModule: FC<IIdeaModuleProps> = (props) => {

const backgroundColor =
statusStyles[statusValue]?.backgroundColor || 'var(--colorNeutralBackground2)'
const borderColor = statusStyles[statusValue]?.borderColor || 'var(--colorNeutralBorder2)'
const borderColor = statusStyles[statusValue]?.borderColor || 'var(--colorNeutralBackground4)'

const fieldValues = isInProcessing
? state.selectedIdea.processingFieldValues
Expand Down Expand Up @@ -236,10 +236,9 @@ export const IdeaModule: FC<IIdeaModuleProps> = (props) => {
</AccordionHeader>
<AccordionPanel>
<div className={styles.idea}>
{state.selectedIdea.registeredFieldValues
.map((model, idx) => (
<IdeaField key={idx} model={model} />
))}
{state.selectedIdea.registeredFieldValues.map((model, idx) => (
<IdeaField key={idx} model={model} />
))}
</div>
</AccordionPanel>
</AccordionItem>
Expand Down

0 comments on commit 5cfa41c

Please sign in to comment.