import React, {FC, useState, useEffect} from 'react'; import {Link} from 'react-router-dom'; import Routes from '../constants/routes'; // Redux import {enhance, selectProfile} from '../store/firebase'; import {WithFirebaseProps, isLoaded, isEmpty} from 'react-redux-firebase'; // Style import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import { faTwitter, faFacebook, faYoutube, faLinkedin, faInstagram, } from '@fortawesome/free-brands-svg-icons'; import FormHeader from '../components/FormHeader'; import Statuses from '../constants/statuses'; // Form import useForm from '../hooks'; import User from '../models/User'; import Dev from '../models/Dev'; import Links from '../types/Links'; import {useSelector} from 'react-redux'; interface FormData { status: string; company: string; website: string; location: string; skills: string; github: string; bio: string; facebook: string; linkedin: string; instagram: string; twitter: string; youtube: string; } interface IProps extends Dev, WithFirebaseProps {} /** * Form to update dev's personal information. */ const EditProfile: FC = ({ firebase, status, skills, company, links, location, bio, }) => { const [showLinks, setShowLinks] = useState(false); const [variable, setVariable] = useState(useSelector(selectProfile)); const initFormData = { status: status ?? 'Developer', company: company, location: location ?? '', bio: bio ?? '', skills: skills?.toString() ?? '', website: links?.website ?? '', github: links?.github ?? '', facebook: links?.facebook ?? '', linkedin: links?.linkedin ?? '', instagram: links?.instagram ?? '', twitter: links?.twitter ?? '', youtube: links?.youtube ?? '', }; const {formData, handleChange, resetForm} = useForm(initFormData); console.log(company, formData.company, variable, isEmpty(firebase.auth)); /** construct profile object from formData */ const makeProfile = ({ status, company, location, bio, website, instagram, facebook, linkedin, twitter, github, youtube, skills, }: FormData) => { const newLinks: Links = { website, instagram, facebook, linkedin, twitter, github, youtube, }; const newSkills: string[] = skills?.split(','); return { status, company, location, bio, links: newLinks, skills: newSkills, }; }; const handleSubmit = (e: React.FormEvent): void => { e.preventDefault(); const updatedDev = makeProfile(formData); firebase.updateProfile(updatedDev, {useSet: true, merge: true}); console.log(`Submitted ${JSON.stringify(formData, null, 2)}`); resetForm(); }; const isDisabled: boolean = formData.status === '' || formData.skills === ''; const toggleSocialLinks = () => setShowLinks(!showLinks); return (
Give us an idea of where you are at in your career
Could be your own company or one you work for
Could be your own or a company website
City & state suggested (eg. Boston, MA)
Please use comma separated values (eg. HTML,CSS,JavaScript,PHP)
If you want your latest repos and a Github link, include your username
Tell us a little about yourself
Optional
{showLinks && ( <>
)} Go Back
); }; export default enhance(EditProfile);