Skip to content

Commit

Permalink
Merge pull request #320 from AkshataKatwal16/relese-changes
Browse files Browse the repository at this point in the history
Issue feat PS-2463:Remove action button(add, edit, delete) in archive section
  • Loading branch information
itsvick authored Nov 14, 2024
2 parents f9afdaa + 63478ba commit 1927147
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/components/HeaderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const HeaderComponent = ({
const [initialDistrict, setInitialDistrict] = useState<any>("");
const [initialBlock, setInitialBlock] = useState<string>("");
const [initialized, setInitialized] = useState(false);
const isArchived = useSubmittedButtonStore(
(state: any) => state.isArchived
);

const [blocks, setBlocks] = useState<Block[]>([]);
const selectedBlockStore = useSubmittedButtonStore(
Expand Down Expand Up @@ -695,7 +698,7 @@ const HeaderComponent = ({
placeholder={searchPlaceHolder}
/>
</Box>
{showAddNew && (
{showAddNew && !isArchived && (
<Box
display={"flex"}
gap={1}
Expand Down
19 changes: 15 additions & 4 deletions src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ const UserTable: React.FC<UserTableProps> = ({
const setSelectedCenterStore = useSubmittedButtonStore(
(state: any) => state.setSelectedCenterStore
);


const isArchived = useSubmittedButtonStore(
(state: any) => state.isArchived
);
const setIsArchived = useSubmittedButtonStore(
(state: any) => state.setIsArchived
);


const [selectedStateCode, setSelectedStateCode] = useState("");
Expand Down Expand Up @@ -361,17 +365,24 @@ const UserTable: React.FC<UserTableProps> = ({
...prevFilters,
status: [Status.ACTIVE],
}));
setIsArchived(false);

} else if (newValue === Status.ARCHIVED) {
setFilters((prevFilters) => ({
...prevFilters,
status: [Status.ARCHIVED],
}));
setIsArchived(true);

} else {
setIsArchived(false);

setFilters((prevFilters) => {
const { status, ...restFilters } = prevFilters;
return {
...restFilters,
};

});
}
console.log(filters);
Expand Down Expand Up @@ -1572,8 +1583,8 @@ console.log(selectedBlockStore)
<KaTableComponent
columns={
role === Role.TEAM_LEADER
? getTLTableColumns(t, isMobile)
: getUserTableColumns(t, isMobile)
? getTLTableColumns(t, isMobile, isArchived)
: getUserTableColumns(t, isMobile, isArchived)
}
reassignCohort={handleReassignCohort}
data={data}
Expand Down
22 changes: 14 additions & 8 deletions src/data/tableColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const generateColumns = (
}));
};

export const getUserTableColumns = (t: any, isMobile: boolean) => {
export const getUserTableColumns = (t: any, isMobile: boolean, isArchived?:any) => {



const configs: ColumnConfig[] = [
{ key: "name", titleKey: "TABLE_TITLE.NAME", width: 130 },
{ key: "age", titleKey: "TABLE_TITLE.AGE", width: 70 },
Expand All @@ -40,7 +43,7 @@ export const getUserTableColumns = (t: any, isMobile: boolean) => {
{ key: "updatedAt", titleKey: "TABLE_TITLE.UPDATED_DATE", width: 160 },
];
// Conditionally add the "actions" column if isActiveYear is true
if (isActiveYear) {
if (isActiveYear && !isArchived) {
configs.push({
key: "actions",
titleKey: "TABLE_TITLE.ACTIONS",
Expand All @@ -52,7 +55,8 @@ export const getUserTableColumns = (t: any, isMobile: boolean) => {
return generateColumns(t, configs, isMobile);
};

export const getTLTableColumns = (t: any, isMobile: boolean) => {
export const getTLTableColumns = (t: any, isMobile: boolean, isArchived:any) => {

const configs: ColumnConfig[] = [
{ key: "name", titleKey: "TABLE_TITLE.NAME", width: 130 },
{ key: "age", titleKey: "TABLE_TITLE.AGE", width: 70 },
Expand All @@ -65,7 +69,7 @@ export const getTLTableColumns = (t: any, isMobile: boolean) => {
{ key: "updatedAt", titleKey: "TABLE_TITLE.UPDATED_DATE", width: 160 },
];
// Conditionally add the "actions" column if isActiveYear is true
if (isActiveYear) {
if (isActiveYear && !isArchived) {
configs.push({
key: "actions",
titleKey: "TABLE_TITLE.ACTIONS",
Expand All @@ -77,7 +81,8 @@ export const getTLTableColumns = (t: any, isMobile: boolean) => {
return generateColumns(t, configs, isMobile);
};

export const getCenterTableData = (t: any, isMobile: boolean) => {
export const getCenterTableData = (t: any, isMobile: boolean, isArchived:any) => {

const configs: ColumnConfig[] = [
{ key: "name", titleKey: "TABLE_TITLE.NAME", width: 130 },
{ key: "customFieldValues", titleKey: "TABLE_TITLE.TYPE", width: 130 },
Expand All @@ -98,7 +103,7 @@ export const getCenterTableData = (t: any, isMobile: boolean) => {
},
];
// Conditionally add the "actions" column if isActiveYear is true
if (isActiveYear) {
if (isActiveYear && !isArchived) {
configs.push({
key: "actions",
titleKey: "TABLE_TITLE.ACTIONS",
Expand Down Expand Up @@ -183,7 +188,8 @@ export const getDistrictTableData = (t: any, isMobile: boolean) => {
return generateColumns(t, configs, isMobile);
};

export const getBlockTableData = (t: any, isMobile: boolean) => {
export const getBlockTableData = (t: any, isMobile: boolean, isArchived?:any) => {

const configs: ColumnConfig[] = [
{ key: "name", titleKey: t("TABLE_TITLE.BLOCK").toUpperCase(), width: 130 },
{ key: "code", titleKey: t("TABLE_TITLE.CODE").toUpperCase(), width: 130 },
Expand All @@ -208,7 +214,7 @@ export const getBlockTableData = (t: any, isMobile: boolean) => {
width: 130,
},
];
if (isActiveYear) {
if (isActiveYear && !isArchived) {
configs.push({
key: "actions",
titleKey: t("TABLE_TITLE.ACTIONS").toUpperCase(),
Expand Down
8 changes: 6 additions & 2 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
import "react-circular-progressbar/dist/styles.css";
import { useRouter } from "next/router";
import { TelemetryEventType } from "@/utils/app.constant";
import useSubmittedButtonStore from "@/utils/useSharedState";

function App({ Component, pageProps }: AppProps) {
const router = useRouter();

const setIsArchived = useSubmittedButtonStore(
(state: any) => state.setIsArchived
);
useEffect(() => {
telemetryFactory.init();
}, []);
Expand All @@ -36,6 +39,8 @@ function App({ Component, pageProps }: AppProps) {
if((router.pathname !== "/logout"))
router.push("/logout");
}
setIsArchived(false)


}, [router]);
useEffect(() => {
Expand Down Expand Up @@ -68,7 +73,6 @@ function App({ Component, pageProps }: AppProps) {

// Log initial page load
handleRouteChange(window.location.pathname);

// Subscribe to route changes and log page views
router.events.on('routeChangeComplete', handleRouteChange);

Expand Down
17 changes: 15 additions & 2 deletions src/pages/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { getBlockTableData } from "@/data/tableColumns";
import { Theme } from "@mui/system";
import { telemetryFactory } from "@/utils/telemetry";
import useStore from "@/store/store";
import useSubmittedButtonStore from "@/utils/useSharedState";

type StateDetail = {
name: string | undefined;
Expand Down Expand Up @@ -127,7 +128,12 @@ const Block: React.FC = () => {
const [pageSize, setPageSize] = React.useState<string | number>(10);
const [isFirstVisit, setIsFirstVisit] = useState(true);
const queryClient = useQueryClient();

const isArchived = useSubmittedButtonStore(
(state: any) => state.isArchived
);
const setIsArchived = useSubmittedButtonStore(
(state: any) => state.setIsArchived
);
const [filters, setFilters] = useState({
name: searchKeyword,
states: stateCode,
Expand Down Expand Up @@ -607,23 +613,30 @@ const Block: React.FC = () => {
...prevFilters,
status: [Status.ACTIVE],
}));
setIsArchived(false)
} else if (newValue === Status.ARCHIVED) {
setFilters((prevFilters: any) => ({
...prevFilters,
status: [Status.ARCHIVED],
}));
setIsArchived(true)

} else if (newValue === Status.ALL_LABEL) {
setFilters((prevFilters: any) => ({
...prevFilters,
status: "",
}));
setIsArchived(false)

} else {
setFilters((prevFilters: any) => {
const { status, ...restFilters } = prevFilters;
return {
...restFilters,
};
});
setIsArchived(false)

}

await queryClient.invalidateQueries({
Expand Down Expand Up @@ -1102,7 +1115,7 @@ if(updatedBy)
<Box sx={{ marginTop: 2 }}>
{filteredCohortOptionData().length > 0 ? (
<KaTableComponent
columns={getBlockTableData(t, isMobile)}
columns={getBlockTableData(t, isMobile, isArchived)}
data={filteredCohortOptionData()}
limit={pageLimit}
offset={pageOffset}
Expand Down
17 changes: 16 additions & 1 deletion src/pages/centers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ const Center: React.FC = () => {
const [isEditForm, setIsEditForm] = useState(false);
const [statesInformation, setStatesInformation] = useState<any>([]);
const [selectedRowData, setSelectedRowData] = useState<any>("");
const isArchived = useSubmittedButtonStore(
(state: any) => state.isArchived
);
const setIsArchived = useSubmittedButtonStore(
(state: any) => state.setIsArchived
);
const {
data: cohortFormData,
isLoading: cohortFormDataLoading,
Expand Down Expand Up @@ -777,23 +783,32 @@ const response= await fetchCohortMemberList(data);
...prevFilters,
status: [Status.ACTIVE],
}));
setIsArchived(false);
} else if (newValue === Status.ARCHIVED) {
setFilters((prevFilters) => ({
...prevFilters,
status: [Status.ARCHIVED],
}));
setIsArchived(true);

} else if (newValue === Status.ALL_LABEL) {

setFilters((prevFilters) => ({
...prevFilters,
status: "",
}));
setIsArchived(false);

} else {

setFilters((prevFilters) => {
const { status, ...restFilters } = prevFilters;
return {
...restFilters,
};
});
setIsArchived(false);

}
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
Expand Down Expand Up @@ -1213,7 +1228,7 @@ const response= await fetchCohortMemberList(data);
</Box>
) : cohortData?.length > 0 ? (
<KaTableComponent
columns={getCenterTableData(t, isMobile)}
columns={getCenterTableData(t, isMobile, isArchived)}
data={cohortData}
limit={pageLimit}
offset={pageOffset}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/useSharedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const useSubmittedButtonStore = create((set) => ({

selectedCenterStore:"",
setSelectedCenterStore: (status: string) => set({ selectedCenterStore: status }),
isArchived:false,
setIsArchived: (status: string) => set({ isArchived: status }),




Expand Down

0 comments on commit 1927147

Please sign in to comment.