Skip to content

Commit

Permalink
[frontend] Fix Impossible to add an override for a new user who doesn…
Browse files Browse the repository at this point in the history
…'t have an initialized user confidence level. (#6837)
  • Loading branch information
SarahBocognano authored and Kedae committed May 2, 2024
1 parent 2f9a1b6 commit 8aeab0d
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,27 @@ const UserEditionConfidence: FunctionComponent<UserEditionConfidenceProps> = ({

const handleSubmitOverride = (index: number, value: OverrideFormData | null) => {
const name = `overrides[${index}]`;
if (isNotEmptyField(value) && value.entity_type && isNotEmptyField(value.max_confidence)) {
if (!user.user_confidence_level) {
// If there is no user_confidence_level defined and value is provided, initialize it with an override
if (isNotEmptyField(value) && value.entity_type && isNotEmptyField(value.max_confidence)) {
commitFieldPatch({
variables: {
id: user.id,
input: {
key: 'user_confidence_level',
value: {
max_confidence: null, // Initialize max_confidence as null
overrides: [{
entity_type: value.entity_type,
max_confidence: parseInt(value.max_confidence ?? '0', 10),
}],
},
},
},
});
}
} else if (isNotEmptyField(value) && value.entity_type && isNotEmptyField(value.max_confidence)) {
// If user_confidence_level already exists, just update or add the override
userConfidenceValidation(t_i18n)
.validateAt(name, { [name]: value })
.then(() => {
Expand All @@ -126,7 +146,7 @@ const UserEditionConfidence: FunctionComponent<UserEditionConfidenceProps> = ({
});
})
.catch(() => false);
} else {
} else if (!isNotEmptyField(value)) {
commitFieldPatch({
variables: {
id: user.id,
Expand Down

0 comments on commit 8aeab0d

Please sign in to comment.