[WEB-4693] fix: remove initial load flicker on auto-archive and auto-close automation page (#7578)
* [WEB-4693] fix: remove initial load flicker on auto-archive and auto-close automation page * refactor: optimize auto-archive and auto-close status calculations using useMemo * chore: add requested changes
This commit is contained in:
parent
34c6047d80
commit
9cf564caae
2 changed files with 16 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { ArchiveRestore } from "lucide-react";
|
||||
|
|
@ -48,6 +48,11 @@ export const AutoArchiveAutomation: React.FC<Props> = observer((props) => {
|
|||
currentProjectDetails?.id
|
||||
);
|
||||
|
||||
const autoArchiveStatus = useMemo(() => {
|
||||
if (currentProjectDetails?.archive_in === undefined) return false;
|
||||
return currentProjectDetails.archive_in !== 0;
|
||||
}, [currentProjectDetails]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SelectMonthModal
|
||||
|
|
@ -71,7 +76,7 @@ export const AutoArchiveAutomation: React.FC<Props> = observer((props) => {
|
|||
</div>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
value={currentProjectDetails?.archive_in !== 0}
|
||||
value={autoArchiveStatus}
|
||||
onChange={async () => {
|
||||
if (currentProjectDetails?.archive_in === 0) {
|
||||
await handleChange({ archive_in: 1 });
|
||||
|
|
@ -94,7 +99,7 @@ export const AutoArchiveAutomation: React.FC<Props> = observer((props) => {
|
|||
</div>
|
||||
|
||||
{currentProjectDetails ? (
|
||||
currentProjectDetails.archive_in !== 0 && (
|
||||
autoArchiveStatus && (
|
||||
<div className="mx-6">
|
||||
<div className="flex w-full items-center justify-between gap-2 rounded border border-custom-border-200 bg-custom-background-90 px-5 py-4">
|
||||
<div className="w-1/2 text-sm font-medium">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import React, { useState } from "react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { useParams } from "next/navigation";
|
||||
// icons
|
||||
|
|
@ -75,6 +75,11 @@ export const AutoCloseAutomation: React.FC<Props> = observer((props) => {
|
|||
currentProjectDetails?.id
|
||||
);
|
||||
|
||||
const autoCloseStatus = useMemo(() => {
|
||||
if (currentProjectDetails?.close_in === undefined) return false;
|
||||
return currentProjectDetails.close_in !== 0;
|
||||
}, [currentProjectDetails]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SelectMonthModal
|
||||
|
|
@ -98,7 +103,7 @@ export const AutoCloseAutomation: React.FC<Props> = observer((props) => {
|
|||
</div>
|
||||
</div>
|
||||
<ToggleSwitch
|
||||
value={currentProjectDetails?.close_in !== 0}
|
||||
value={autoCloseStatus}
|
||||
onChange={async () => {
|
||||
if (currentProjectDetails?.close_in === 0) {
|
||||
await handleChange({ close_in: 1, default_state: defaultState });
|
||||
|
|
@ -121,7 +126,7 @@ export const AutoCloseAutomation: React.FC<Props> = observer((props) => {
|
|||
</div>
|
||||
|
||||
{currentProjectDetails ? (
|
||||
currentProjectDetails.close_in !== 0 && (
|
||||
autoCloseStatus && (
|
||||
<div className="mx-6">
|
||||
<div className="flex flex-col rounded border border-custom-border-200 bg-custom-background-90">
|
||||
<div className="flex w-full items-center justify-between gap-2 px-5 py-4">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue