-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikita Kakuev
committed
Sep 25, 2023
1 parent
94bdb38
commit 74429c6
Showing
6 changed files
with
67 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
import { FormEvent, useContext, useEffect, useState } from "react"; | ||
import cn from "classnames" | ||
import { FormEvent, useContext, useRef } from 'react'; | ||
import cn from 'classnames'; | ||
|
||
import { SpacesContext } from "."; | ||
import { Member } from "../utils/types"; | ||
import { SpacesContext } from '.'; | ||
import { Member } from '../utils/types'; | ||
import { getRandomColor } from '../utils'; | ||
|
||
interface Props { | ||
self?: Member; | ||
isVisible?: boolean | ||
setIsVisible?: (isVisible: boolean) => void | ||
self?: Member; | ||
isVisible?: boolean; | ||
setIsVisible?: (isVisible: boolean) => void; | ||
} | ||
|
||
export const Modal = ({ isVisible = false, setIsVisible, self }: Props) => { | ||
const space = useContext(SpacesContext); | ||
const [value, setValue] = useState(self?.profileData?.name); | ||
|
||
console.log(self?.profileData?.name, value) | ||
|
||
const handleChange = (e: FormEvent<HTMLInputElement>) => { | ||
setValue(e.currentTarget.value) | ||
} | ||
|
||
const handleSubmit = (e: FormEvent) => { | ||
e.preventDefault(); | ||
|
||
if (!space || !setIsVisible) return; | ||
|
||
space.updateProfileData(currentProfile => { | ||
console.log(currentProfile) | ||
return { name: value } | ||
}); | ||
|
||
setIsVisible(false) | ||
} | ||
|
||
useEffect(() => { | ||
setValue(self?.profileData?.name) | ||
}, [self?.profileData?.name]) | ||
|
||
return <div className={cn("backdrop-blur-md bg-black/30 fixed top-0 left-0 w-full h-full flex items-center justify-center transition-all duration-300", { | ||
"opacity-0 pointer-events-none": !isVisible, | ||
"opacity-100": isVisible | ||
})}> | ||
<form onSubmit={handleSubmit} className="bg-white p-8 shadow-lg rounded-[20px]"> | ||
<h3 className="font-semibold text-xl text-center mb-8">Enter your name</h3> | ||
<input value={value} onChange={handleChange} className="border border-gray-300 rounded-md p-2 w-full" /> | ||
<button type="submit" className="bg-ably-black text-white rounded-md p-2 w-full mt-4">Set name</button> | ||
</form> | ||
const space = useContext(SpacesContext); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
const handleSubmit = (e: FormEvent) => { | ||
e.preventDefault(); | ||
|
||
if (!space || !setIsVisible) return; | ||
|
||
space.updateProfileData({ name: inputRef.current?.value, color: getRandomColor() }); | ||
setIsVisible(false); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={cn( | ||
'backdrop-blur-md bg-black/30 fixed top-0 left-0 w-full h-full flex items-center justify-center transition-all duration-300', | ||
{ | ||
'opacity-0 pointer-events-none': !isVisible, | ||
'opacity-100': isVisible, | ||
}, | ||
)} | ||
> | ||
<form | ||
onSubmit={handleSubmit} | ||
className="bg-white p-8 shadow-lg rounded-[20px]" | ||
> | ||
<h3 className="font-semibold text-xl text-center mb-8">Enter your name</h3> | ||
<input | ||
ref={inputRef} | ||
className="border border-gray-300 rounded-md p-2 w-full" | ||
defaultValue={self?.profileData?.name} | ||
/> | ||
<button | ||
type="submit" | ||
className="bg-ably-black text-white rounded-md p-2 w-full mt-4" | ||
> | ||
Set name | ||
</button> | ||
</form> | ||
</div> | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters