Skip to content

Commit

Permalink
fix(console): #1139 owner when editing project (#1213)
Browse files Browse the repository at this point in the history
fix(console): #1139
  • Loading branch information
waynelwz committed Sep 15, 2022
1 parent 54766bc commit 86ca033
Showing 1 changed file with 14 additions and 8 deletions.
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

0 comments on commit 86ca033

Please sign in to comment.