|
| 1 | +import React from "react"; |
| 2 | +import { Title, Space } from "../StyledComponents"; |
| 3 | +import { |
| 4 | + SELECT_SSH_KEY, |
| 5 | + createMessage, |
| 6 | + USER_PROFILE_SETTINGS_TITLE, |
| 7 | + AUTHOR_NAME, |
| 8 | + AUTHOR_EMAIL, |
| 9 | +} from "constants/messages"; |
| 10 | +import OptionSelector from "../OptionSelector"; |
| 11 | +import styled from "styled-components"; |
| 12 | +import { getTypographyByKey } from "constants/DefaultTheme"; |
| 13 | +import TextInput from "components/ads/TextInput"; |
| 14 | +import { AUTH_TYPE, Classes as GitSyncClasses } from "../../constants"; |
| 15 | +import { USER_NAME, USER_PASSWORD } from "../../../../../constants/messages"; |
| 16 | +import Dropdown from "components/ads/Dropdown"; |
| 17 | +import Text, { TextType } from "../../../../../components/ads/Text"; |
| 18 | + |
| 19 | +// Mock Data |
| 20 | +const HTTPS_PROFILE_OPTIONS = [{ label: "PROFILE 1" }, { label: "PROFILE 2" }]; |
| 21 | + |
| 22 | +const SSH_PROFILE_OPTION = [{ label: "PROFILE 1" }, { label: "PROFILE 2" }]; |
| 23 | + |
| 24 | +// |
| 25 | +const LabelContainer = styled.div` |
| 26 | + ${(props) => getTypographyByKey(props, "h6")}; |
| 27 | + display: flex; |
| 28 | + align-items: center; |
| 29 | + margin-bottom: 8px; |
| 30 | +`; |
| 31 | + |
| 32 | +const InputContainer = styled.div` |
| 33 | + width: 70%; |
| 34 | + display: flex; |
| 35 | + align-items: center; |
| 36 | +`; |
| 37 | + |
| 38 | +const TitleWrapper = styled.div` |
| 39 | + display: flex; |
| 40 | + flex-direction: row; |
| 41 | +
|
| 42 | + .${GitSyncClasses.OPTION_SELECTOR_WRAPPER} { |
| 43 | + display: flex; |
| 44 | + align-items: center; |
| 45 | + padding-top: 5px; |
| 46 | + } |
| 47 | +`; |
| 48 | + |
| 49 | +const OptionWrapper = styled.div<{ |
| 50 | + selected: boolean; |
| 51 | +}>` |
| 52 | + padding: ${(props) => props.theme.spaces[2] + 1}px |
| 53 | + ${(props) => props.theme.spaces[5]}px; |
| 54 | + cursor: pointer; |
| 55 | + display: flex; |
| 56 | + align-items: center; |
| 57 | +
|
| 58 | + background-color: ${(props) => |
| 59 | + props.selected ? props.theme.colors.propertyPane.dropdownSelectBg : null}; |
| 60 | +`; |
| 61 | + |
| 62 | +// Child component |
| 63 | +type AuthConfigProps = { |
| 64 | + authType: string; |
| 65 | +}; |
| 66 | + |
| 67 | +function AuthConfig({ authType }: AuthConfigProps) { |
| 68 | + switch (authType) { |
| 69 | + case AUTH_TYPE.SSH: |
| 70 | + return ( |
| 71 | + <> |
| 72 | + <LabelContainer> |
| 73 | + <span className="label">{createMessage(SELECT_SSH_KEY)}</span> |
| 74 | + </LabelContainer> |
| 75 | + <InputContainer> |
| 76 | + <Dropdown |
| 77 | + disabled={SSH_PROFILE_OPTION.length === 0} |
| 78 | + onSelect={() => { |
| 79 | + // |
| 80 | + }} |
| 81 | + // optionWidth="100%" |
| 82 | + options={SSH_PROFILE_OPTION} |
| 83 | + renderOption={({ |
| 84 | + isSelectedNode, |
| 85 | + option, |
| 86 | + optionClickHandler, |
| 87 | + }) => ( |
| 88 | + <OptionWrapper |
| 89 | + onClick={() => |
| 90 | + optionClickHandler && optionClickHandler(option) |
| 91 | + } |
| 92 | + selected={!!isSelectedNode} |
| 93 | + > |
| 94 | + <Text type={TextType.P1}>{option.label}</Text> |
| 95 | + </OptionWrapper> |
| 96 | + )} |
| 97 | + selected={{}} |
| 98 | + showLabelOnly |
| 99 | + width="100%" |
| 100 | + /> |
| 101 | + </InputContainer> |
| 102 | + </> |
| 103 | + ); |
| 104 | + case AUTH_TYPE.HTTPS: |
| 105 | + return ( |
| 106 | + <> |
| 107 | + <LabelContainer> |
| 108 | + <span className="label">{createMessage(USER_NAME)}</span> |
| 109 | + </LabelContainer> |
| 110 | + <InputContainer> |
| 111 | + <TextInput fill /> |
| 112 | + </InputContainer> |
| 113 | + |
| 114 | + <Space size={7} /> |
| 115 | + |
| 116 | + <LabelContainer> |
| 117 | + <span className="label">{createMessage(USER_PASSWORD)}</span> |
| 118 | + </LabelContainer> |
| 119 | + <InputContainer> |
| 120 | + <TextInput fill /> |
| 121 | + </InputContainer> |
| 122 | + </> |
| 123 | + ); |
| 124 | + default: |
| 125 | + return null; |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +// Component |
| 130 | +type UserGitProfileSettingsProps = { |
| 131 | + authType: string; |
| 132 | +}; |
| 133 | + |
| 134 | +function UserGitProfileSettings({ authType }: UserGitProfileSettingsProps) { |
| 135 | + return ( |
| 136 | + <> |
| 137 | + <TitleWrapper> |
| 138 | + <Title>{createMessage(USER_PROFILE_SETTINGS_TITLE)}</Title> |
| 139 | + {authType === AUTH_TYPE.HTTPS ? ( |
| 140 | + <OptionSelector |
| 141 | + options={HTTPS_PROFILE_OPTIONS} |
| 142 | + selected={HTTPS_PROFILE_OPTIONS[0]} |
| 143 | + /> |
| 144 | + ) : null} |
| 145 | + </TitleWrapper> |
| 146 | + |
| 147 | + <Space size={7} /> |
| 148 | + |
| 149 | + <AuthConfig authType={authType} /> |
| 150 | + |
| 151 | + <Space size={7} /> |
| 152 | + |
| 153 | + <LabelContainer> |
| 154 | + <span className="label">{createMessage(AUTHOR_NAME)}</span> |
| 155 | + </LabelContainer> |
| 156 | + <InputContainer> |
| 157 | + <TextInput fill /> |
| 158 | + </InputContainer> |
| 159 | + |
| 160 | + <Space size={7} /> |
| 161 | + |
| 162 | + <LabelContainer> |
| 163 | + <span className="label">{createMessage(AUTHOR_EMAIL)}</span> |
| 164 | + </LabelContainer> |
| 165 | + <InputContainer> |
| 166 | + <TextInput fill /> |
| 167 | + </InputContainer> |
| 168 | + </> |
| 169 | + ); |
| 170 | +} |
| 171 | + |
| 172 | +export default UserGitProfileSettings; |
0 commit comments