Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(console): #1139 owner when editing project #1213

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions console/src/domain/project/components/ProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { RadioGroup, Radio } from 'baseui/radio'
import { FormControl } from 'baseui/form-control'
import { Textarea } from 'baseui/textarea'
import { useCurrentUser } from '@/hooks/useCurrentUser'
import { IUserSchema } from '@user/schemas/user'
import { ICreateProjectSchema, IProjectSchema } from '../schemas/project'

const { Form, FormItem } = createForm<ICreateProjectSchema>()
Expand Down Expand Up @@ -69,16 +70,16 @@ const Visibility = ({ value, onChange }: IVisibilityProps) => {
)
}

type IOwnerProps = IControlledProps
type IOwnerProps = IControlledProps & {
data?: IUserSchema
}

const Owner = ({ value, onChange }: IOwnerProps) => {
// only one option for now
// eslint-disable-next-line react-hooks/exhaustive-deps
const { currentUser } = useCurrentUser()
const Owner = ({ value, onChange, data }: IOwnerProps) => {
return (
<Select
options={[{ label: currentUser?.name, id: currentUser?.id }]}
options={[{ label: data?.name, id: data?.id }]}
value={[{ id: value }]}
clearable={false}
onChange={(o) => onChange?.(o.option?.id as string)}
/>
)
Expand All @@ -88,8 +89,13 @@ export default function ProjectForm({ project, onSubmit }: IProjectFormProps) {
const [t] = useTranslation()
// eslint-disable-next-line react-hooks/exhaustive-deps
const { currentUser } = useCurrentUser()

const user = React.useMemo(() => {
return project?.owner ?? currentUser
}, [project, currentUser])

const [values, setValues] = useState<ICreateProjectSchema | undefined>({
ownerId: currentUser?.id,
ownerId: user?.id,
projectName: project?.name ?? '',
privacy: project?.privacy ?? 'PUBLIC',
description: project?.description ?? '',
Expand Down Expand Up @@ -141,7 +147,7 @@ export default function ProjectForm({ project, onSubmit }: IProjectFormProps) {
marginBottom: 0,
}}
>
<Owner />
<Owner data={user} />
</FormItem>
<div
style={{
Expand Down