/* Copyright (C) 2017 Cloudbase Solutions SRL This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ import { observer } from "mobx-react"; import React from "react"; import { Link } from "react-router"; import styled from "styled-components"; import { ThemePalette, ThemeProps } from "@src/components/Theme"; import Button from "@src/components/ui/Button"; import CopyMultilineValue from "@src/components/ui/CopyMultilineValue"; import CopyValue from "@src/components/ui/CopyValue"; import StatusImage from "@src/components/ui/StatusComponents/StatusImage"; import type { User } from "@src/@types/User"; import type { Project } from "@src/@types/Project"; const Wrapper = styled.div` ${ThemeProps.exactWidth(ThemeProps.contentWidth)} margin: 0 auto; padding-left: 126px; `; const Info = styled.div` display: flex; flex-wrap: wrap; margin-top: 32px; margin-left: -32px; `; const LinkStyled = styled(Link)` color: ${ThemePalette.primary}; text-decoration: none; `; const Field = styled.div` ${ThemeProps.exactWidth("calc(50% - 32px)")} margin-bottom: 32px; margin-left: 32px; `; const Value = styled.div``; const Label = styled.div` font-size: 10px; font-weight: ${ThemeProps.fontWeights.medium}; color: ${ThemePalette.grayscale[3]}; text-transform: uppercase; margin-bottom: 3px; `; const LoadingWrapper = styled.div` display: flex; justify-content: center; width: 100%; margin: 32px 0 64px 0; `; const Buttons = styled.div` margin-top: 64px; display: flex; justify-content: space-between; `; const ButtonsColumn = styled.div` display: flex; flex-direction: column; button { margin-bottom: 16px; &:last-child { margin-bottom: 0; } } `; export type Props = { user: User | null; loading: boolean; projects: Project[]; userProjects: Project[]; isLoggedUser: boolean; onUpdatePasswordClick: () => void; onDeleteClick: () => void; }; @observer class UserDetailsContent extends React.Component { renderLoading() { if (!this.props.loading) { return null; } return ( ); } renderButtons() { if (this.props.loading) return null; return ( ); } renderUserProjects( projects: { label: string; id: string }[] ): React.ReactNode { return projects.map((project, i) => ( {project.label ? ( {project.label} ) : ( project.id )} {i < projects.length - 1 ? ", " : ""} )); } renderInfo() { if (this.props.loading || !this.props.user) { return null; } const { user } = this.props; const primaryProject = this.props.projects.find( p => user.project_id === p.id ); const primaryProjectName = primaryProject ? primaryProject.name : user.project_id; const userProjects: { label: string; id: string }[] = this.props.userProjects.map(up => { const projectInfo = this.props.projects.find(p => p.id === up.id); if (projectInfo) { return { label: projectInfo.name, id: up.id }; } return { label: "", id: up.id }; }); return ( {this.renderValue(user.name)} {user.description ? ( ) : ( - )} {this.renderValue(user.id)} {this.renderValue(user.email || "-")} {this.renderValue(primaryProjectName || "-")} {userProjects.length > 0 ? ( this.renderUserProjects(userProjects) ) : ( - )} {user.enabled ? "Yes" : "No"} ); } renderValue(value: string) { return value !== "-" ? ( ) : ( {value} ); } render() { return ( {this.renderInfo()} {this.renderLoading()} {this.renderButtons()} ); } } export default UserDetailsContent;