Skip to content

Commit

Permalink
fix(1-3173): reset tag list when you submit it
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Dec 10, 2024
1 parent c860d8e commit bd06748
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useReducer, useState, type VFC } from 'react';
import { type FC, useEffect, useReducer, useState } from 'react';
import { Link as RouterLink } from 'react-router-dom';
import {
type AutocompleteProps,
Expand Down Expand Up @@ -56,7 +56,8 @@ const payloadReducer = (
| {
type: 'clear';
payload: ITag[];
},
}
| { type: 'reset' },
) => {
switch (action.type) {
case 'add':
Expand All @@ -76,6 +77,11 @@ const payloadReducer = (
addedTags: [],
removedTags: action.payload,
};
case 'reset':
return {
addedTags: [],
removedTags: [],
};
default:
return state;
}
Expand All @@ -87,7 +93,7 @@ const emptyTagType = {
icon: '',
};

export const ManageBulkTagsDialog: VFC<IManageBulkTagsDialogProps> = ({
export const ManageBulkTagsDialog: FC<IManageBulkTagsDialogProps> = ({
open,
initialValues,
initialIndeterminateValues,
Expand All @@ -106,6 +112,13 @@ export const ManageBulkTagsDialog: VFC<IManageBulkTagsDialogProps> = ({
removedTags: [],
});

console.log(payload);

const modifiedOnSubmit = (payload: Payload) => {
onSubmit(payload);
dispatch({ type: 'reset' });
};

const resetTagType = (
tagType: ITagType = tagTypes.length > 0 ? tagTypes[0] : emptyTagType,
) => {
Expand Down Expand Up @@ -230,7 +243,7 @@ export const ManageBulkTagsDialog: VFC<IManageBulkTagsDialogProps> = ({
secondaryButtonText='Cancel'
primaryButtonText='Save tags'
title='Update feature flag tags'
onClick={() => onSubmit(payload)}
onClick={() => modifiedOnSubmit(payload)}
disabledPrimaryButton={
payload.addedTags.length === 0 &&
payload.removedTags.length === 0
Expand All @@ -244,7 +257,7 @@ export const ManageBulkTagsDialog: VFC<IManageBulkTagsDialogProps> = ({
>
Tags allow you to group features together
</Typography>
<form id={formId} onSubmit={() => onSubmit(payload)}>
<form id={formId} onSubmit={() => modifiedOnSubmit(payload)}>
<StyledDialogFormContent>
<TagTypeSelect
key={tagTypesLoading ? 'loading' : tagTypes.length}
Expand Down

0 comments on commit bd06748

Please sign in to comment.