|
| 1 | +// SPDX-FileCopyrightText: 2022 Dusan Mijatovic (dv4all) |
| 2 | +// SPDX-FileCopyrightText: 2022 dv4all |
| 3 | +// |
| 4 | +// SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +import {useState} from 'react' |
| 7 | +import useTheme from '@mui/material/styles/useTheme' |
| 8 | +import useMediaQuery from '@mui/material/useMediaQuery' |
| 9 | +import Dialog from '@mui/material/Dialog' |
| 10 | +import MailOutlineOutlined from '@mui/icons-material/MailOutlineOutlined' |
| 11 | + |
| 12 | +import {config,organisationSignUp} from './config' |
| 13 | +import useRsdSettings from '~/config/useRsdSettings' |
| 14 | +import {useForm} from 'react-hook-form' |
| 15 | + |
| 16 | +type SignUpOrganisation = { |
| 17 | + name: string, |
| 18 | + organisation: string, |
| 19 | + role: string, |
| 20 | + description: string |
| 21 | +} |
| 22 | + |
| 23 | +const inputClasses='mb-4 placeholder:text-gray-500 outline-0 p-2 w-full text-sm bg-transparent text-white border border-gray-600 rounded-sm' |
| 24 | + |
| 25 | +export default function OrganisationSignUp({minWidth = '9rem'}:{minWidth:string}) { |
| 26 | + const theme = useTheme() |
| 27 | + const fullScreen = useMediaQuery(theme.breakpoints.down('sm')) |
| 28 | + const {host} = useRsdSettings() |
| 29 | + const [open, setOpen] = useState(false) |
| 30 | + |
| 31 | + const {register, watch, reset} = useForm<SignUpOrganisation>({ |
| 32 | + mode: 'onChange', |
| 33 | + defaultValues: { |
| 34 | + name:'', |
| 35 | + organisation: '', |
| 36 | + role:'', |
| 37 | + description: '' |
| 38 | + } |
| 39 | + }) |
| 40 | + |
| 41 | + const [name,organisation,role,description] = watch(['name','organisation','role','description']) |
| 42 | + |
| 43 | + // console.group('Organisation Sing Up') |
| 44 | + // console.log('name...', name) |
| 45 | + // console.log('organisation...', organisation) |
| 46 | + // console.log('description...', description) |
| 47 | + // console.groupEnd() |
| 48 | + |
| 49 | + function mailBody(): string | undefined { |
| 50 | + return encodeURIComponent(`Hi RSD team, |
| 51 | +
|
| 52 | + I would like to add my organisation to RSD! |
| 53 | +
|
| 54 | + ------------------------- |
| 55 | + Name: ${name} |
| 56 | + Organisation: ${organisation} |
| 57 | + Professional role: ${role} |
| 58 | + ------------------------- |
| 59 | +
|
| 60 | + ${description} |
| 61 | + `) |
| 62 | + } |
| 63 | + |
| 64 | + function closeAndReset() { |
| 65 | + setOpen(false) |
| 66 | + // reset form after all processes settled |
| 67 | + // we need to wait for mailBody function |
| 68 | + setTimeout(() => { |
| 69 | + reset() |
| 70 | + },0) |
| 71 | + } |
| 72 | + |
| 73 | + return ( |
| 74 | + <> |
| 75 | + <button |
| 76 | + aria-describedby="Sign up button" |
| 77 | + onClick={()=>setOpen(true)} |
| 78 | + > |
| 79 | + <div className="relative group"> |
| 80 | + <div |
| 81 | + className="absolute -inset-1 bg-gradient-to-r from-purple-600 to-pink-600 rounded-lg blur opacity-25 group-hover:opacity-100 transition duration-1000 group-hover:duration-300"/> |
| 82 | + <div |
| 83 | + className="flex gap-3 text-black relative px-8 py-3 bg-white ring-1 ring-gray-900/5 rounded leading-none items-center justify-center space-x-2" |
| 84 | + style={{ |
| 85 | + minWidth |
| 86 | + }} |
| 87 | + > |
| 88 | + <span className="space-y-2 text-xl font-medium whitespace-nowrap"> |
| 89 | + {config.button.register.label} |
| 90 | + </span> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + </button> |
| 94 | + <Dialog |
| 95 | + fullScreen={fullScreen} |
| 96 | + open={open} |
| 97 | + onClose={()=>setOpen(false)} |
| 98 | + aria-labelledby="responsive-dialog-title" |
| 99 | + > |
| 100 | + <div className="h-full w-full bg-[#232323] p-6"> |
| 101 | + <div className="mx-auto"> |
| 102 | + <div className="text-white text-xl mb-4"> |
| 103 | + {config.button.register.label} |
| 104 | + </div> |
| 105 | + <div className="text-sm text-[#B7B7B7] pb-4"> |
| 106 | + You can find more information about registering your organisation in our <u><a href="https://research-software-directory.github.io/documentation/register-organization.html" target="_blank" rel="noreferrer">documentation</a></u>. |
| 107 | + </div> |
| 108 | + {/* INPUTS */} |
| 109 | + <input type="text" |
| 110 | + autoFocus={true} |
| 111 | + autoComplete="off" |
| 112 | + className={inputClasses} |
| 113 | + placeholder={organisationSignUp.name.label} |
| 114 | + {...register('name')} |
| 115 | + /> |
| 116 | + <input type="text" |
| 117 | + autoComplete="off" |
| 118 | + className={inputClasses} |
| 119 | + placeholder={organisationSignUp.organisation.label} |
| 120 | + {...register('organisation')} |
| 121 | + /> |
| 122 | + <input type="text" |
| 123 | + autoComplete="off" |
| 124 | + className={inputClasses} |
| 125 | + placeholder={organisationSignUp.role.label} |
| 126 | + {...register('role')} |
| 127 | + /> |
| 128 | + <textarea |
| 129 | + rows={5} |
| 130 | + className={inputClasses} |
| 131 | + placeholder={organisationSignUp.description.label} |
| 132 | + {...register('description')} |
| 133 | + > |
| 134 | + </textarea> |
| 135 | + {/* NOTIFICATIONS */} |
| 136 | + <div className="text-sm text-[#B7B7B7] pb-4"> |
| 137 | + {organisationSignUp.notification[0]} <br/> |
| 138 | + {organisationSignUp.notification[1]} |
| 139 | + </div> |
| 140 | + {/* NAVIGATION */} |
| 141 | + <div className="flex justify-end items-center gap-4 my-2"> |
| 142 | + <button |
| 143 | + className="text-sm text-white border border-gray-500 text-opacity-60 rounded px-4 py-1 hover:opacity-90 active:opacity-95" |
| 144 | + onClick={closeAndReset}> |
| 145 | + Cancel |
| 146 | + </button> |
| 147 | + <a |
| 148 | + role="button" |
| 149 | + type="submit" |
| 150 | + onClick={closeAndReset} |
| 151 | + className="text-sm text-white hover:text-white bg-primary px-4 py-1 rounded hover:opacity-90 active:opacity-95" |
| 152 | + target="_blank" |
| 153 | + rel="noreferrer" |
| 154 | + href={`mailto:${host.email}?subject=${encodeURIComponent(config.button.register.label)}&body=${mailBody()}`} |
| 155 | + > |
| 156 | + <MailOutlineOutlined/> Create email * |
| 157 | + </a> |
| 158 | + </div> |
| 159 | + </div> |
| 160 | + </div> |
| 161 | + </Dialog> |
| 162 | + </> |
| 163 | + ) |
| 164 | +} |
0 commit comments