2024-07-30 09:09:49 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2023-08-28 15:37:32 +00:00
|
|
|
import PageWrapper from "pages/common/PageWrapper";
|
2021-03-04 09:37:02 +00:00
|
|
|
import styled from "styled-components";
|
2024-08-09 14:20:29 +00:00
|
|
|
import { Tabs, Tab, TabsList, TabPanel } from "@appsmith/ads";
|
2021-03-04 09:37:02 +00:00
|
|
|
import General from "./General";
|
2025-01-05 10:21:23 +00:00
|
|
|
import OldGitConfig from "./GitConfig";
|
2021-10-20 07:38:17 +00:00
|
|
|
import { useLocation } from "react-router";
|
|
|
|
|
import { GIT_PROFILE_ROUTE } from "constants/routes";
|
2023-05-19 18:37:06 +00:00
|
|
|
import { BackButton } from "components/utils/helperComponents";
|
2024-07-30 09:09:49 +00:00
|
|
|
import { useDispatch } from "react-redux";
|
|
|
|
|
import { fetchGlobalGitConfigInit } from "actions/gitSyncActions";
|
2025-01-05 10:21:23 +00:00
|
|
|
import { useGitModEnabled } from "pages/Editor/gitSync/hooks/modHooks";
|
2025-02-18 12:33:31 +00:00
|
|
|
import { GitGlobalProfile as GitGlobalProfileNew } from "git";
|
|
|
|
|
import { gitFetchGlobalProfile } from "git/store";
|
2025-01-05 10:21:23 +00:00
|
|
|
|
|
|
|
|
function GitGlobalProfile() {
|
|
|
|
|
const isGitModEnabled = useGitModEnabled();
|
|
|
|
|
|
|
|
|
|
return isGitModEnabled ? <GitGlobalProfileNew /> : <OldGitConfig />;
|
|
|
|
|
}
|
2021-03-04 09:37:02 +00:00
|
|
|
|
|
|
|
|
const ProfileWrapper = styled.div`
|
2023-05-19 18:37:06 +00:00
|
|
|
width: 978px;
|
|
|
|
|
margin: var(--ads-v2-spaces-7) auto;
|
|
|
|
|
padding-left: var(--ads-v2-spaces-7);
|
2022-10-04 11:18:35 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
.tab-item {
|
|
|
|
|
display: flex;
|
|
|
|
|
gap: 5px;
|
|
|
|
|
align-items: center;
|
2021-03-04 09:37:02 +00:00
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
function UserProfile() {
|
2021-10-20 07:38:17 +00:00
|
|
|
const location = useLocation();
|
2024-07-30 09:09:49 +00:00
|
|
|
const dispatch = useDispatch();
|
2025-01-05 10:21:23 +00:00
|
|
|
const isGitModEnabled = useGitModEnabled();
|
2021-10-20 07:38:17 +00:00
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
let initialTab = "general";
|
|
|
|
|
const tabs = [
|
2021-03-04 09:37:02 +00:00
|
|
|
{
|
|
|
|
|
key: "general",
|
|
|
|
|
title: "General",
|
|
|
|
|
panelComponent: <General />,
|
|
|
|
|
icon: "general",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2022-11-01 14:59:42 +00:00
|
|
|
tabs.push({
|
|
|
|
|
key: "gitConfig",
|
|
|
|
|
title: "Git user config",
|
2025-01-05 10:21:23 +00:00
|
|
|
panelComponent: <GitGlobalProfile />,
|
2022-11-01 14:59:42 +00:00
|
|
|
icon: "git-branch",
|
|
|
|
|
});
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2022-11-01 14:59:42 +00:00
|
|
|
if (location.pathname === GIT_PROFILE_ROUTE) {
|
2023-05-19 18:37:06 +00:00
|
|
|
initialTab = "gitConfig";
|
2021-09-17 10:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-19 18:37:06 +00:00
|
|
|
const [selectedTab, setSelectedTab] = useState(initialTab);
|
2021-10-20 07:38:17 +00:00
|
|
|
|
2025-01-05 10:21:23 +00:00
|
|
|
useEffect(
|
|
|
|
|
function fetchGlobalGitConfigOnInitEffect() {
|
|
|
|
|
if (isGitModEnabled) {
|
2025-02-18 12:33:31 +00:00
|
|
|
dispatch(gitFetchGlobalProfile());
|
2025-01-05 10:21:23 +00:00
|
|
|
} else {
|
|
|
|
|
dispatch(fetchGlobalGitConfigInit());
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[dispatch, isGitModEnabled],
|
|
|
|
|
);
|
2024-07-30 09:09:49 +00:00
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
return (
|
|
|
|
|
<PageWrapper displayName={"Profile"}>
|
|
|
|
|
<ProfileWrapper>
|
2024-09-09 23:22:23 +00:00
|
|
|
<BackButton />
|
2023-05-19 18:37:06 +00:00
|
|
|
<Tabs defaultValue={selectedTab} onValueChange={setSelectedTab}>
|
|
|
|
|
<TabsList>
|
|
|
|
|
{tabs.map((tab) => {
|
|
|
|
|
return (
|
|
|
|
|
<Tab key={tab.key} value={tab.key}>
|
|
|
|
|
<div className="tab-item">{tab.title}</div>
|
|
|
|
|
</Tab>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</TabsList>
|
|
|
|
|
{tabs.map((tab) => {
|
|
|
|
|
return (
|
|
|
|
|
<TabPanel key={tab.key} value={tab.key}>
|
|
|
|
|
{tab.panelComponent}
|
|
|
|
|
</TabPanel>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Tabs>
|
2021-03-04 09:37:02 +00:00
|
|
|
</ProfileWrapper>
|
|
|
|
|
</PageWrapper>
|
|
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2021-03-04 09:37:02 +00:00
|
|
|
|
|
|
|
|
export default UserProfile;
|