Skip to content

Commit

Permalink
fix: Duplicated segment conditions on save (#4726)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Oct 15, 2024
1 parent cbd08f3 commit 8825971
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
15 changes: 11 additions & 4 deletions frontend/web/components/modals/CreateSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ const CreateSegment: FC<CreateSegmentType> = ({
],
}
const [segment, setSegment] = useState(_segment || defaultSegment)
const [description, setDescription] = useState(segment.description)
const [name, setName] = useState<Segment['name']>(segment.name)
const [rules, setRules] = useState<Segment['rules']>(segment.rules)
useEffect(() => {
if (segment) {
setRules(segment.rules)
setDescription(segment.description)
setName(segment.name)
}
}, [segment])
const isEdit = !!segment.id
const [
createSegment,
Expand All @@ -147,17 +157,13 @@ const CreateSegment: FC<CreateSegmentType> = ({

const isSaving = creating || updating
const [showDescriptions, setShowDescriptions] = useState(false)
const [description, setDescription] = useState(segment.description)
const [name, setName] = useState<Segment['name']>(segment.name)
const [rules, setRules] = useState<Segment['rules']>(segment.rules)
const [tab, setTab] = useState(0)
const [metadata, setMetadata] = useState<CustomMetadataField[]>(
segment.metadata,
)
const metadataEnable =
Utils.getPlansPermission('METADATA') &&
Utils.getFlagsmithHasFeature('enable_metadata')

const error = createError || updateError
const totalSegments = ProjectStore.getTotalSegments() ?? 0
const maxSegmentsAllowed = ProjectStore.getMaxSegmentsAllowed() ?? 0
Expand Down Expand Up @@ -284,6 +290,7 @@ const CreateSegment: FC<CreateSegmentType> = ({
}, [createSuccess])
useEffect(() => {
if (updateSuccess && updateSegmentData) {
setSegment(updateSegmentData)
onComplete?.(updateSegmentData)
}
//eslint-disable-next-line
Expand Down
1 change: 0 additions & 1 deletion frontend/web/components/pages/SegmentsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const SegmentsPage: FC<SegmentsPageType> = (props) => {
params.featureSpecific === 'true',
)

console.log('id is', id)
useEffect(() => {
if (id) {
editSegment(id, !manageSegmentsPermission)
Expand Down

0 comments on commit 8825971

Please sign in to comment.