Commit 18d1dbbd authored by nickstiffler's avatar nickstiffler Committed by Yannis Barlas

feat(user profile): add orcid to user

parent e5adb1c5
......@@ -18,6 +18,7 @@ const GET_CURRENT_USER_PROFILE = gql`
givenNames
surname
username
orcid
}
}
`
......
......@@ -81,6 +81,10 @@ const EmailInput = props => (
/>
)
const OrcidInput = props => (
<TextField label="ORCID iD" {...props.field} placeholder="Optional" />
)
const PasswordInput = props => (
<TextField
label="Password"
......@@ -131,6 +135,7 @@ const Signup = ({ values, handleSubmit, status, logo = null }) => {
<Field component={GivenNamesInput} name="givenNames" />
<Field component={SurnameInput} name="surname" />
<Field component={EmailInput} name="email" />
<Field component={OrcidInput} name="orcid" />
<Field component={PasswordInput} name="password" />
<Button primary type="submit">
Sign up
......
......@@ -7,6 +7,7 @@ const SIGNUP_USER = gql`
type
username
email
orcid
}
}
`
......
......@@ -39,15 +39,17 @@ const SectionHeader = styled(H5)`
`
const PersonalInformation = props => {
const { givenNames, surname, update } = props
const { givenNames, surname, update, orcid } = props
const initialValues = {
givenNames,
orcid,
surname,
}
const validations = yup.object().shape({
givenNames: yup.string().required('Given names are required'),
orcid: yup.string(),
surname: yup.string().required('Surname is required'),
})
......@@ -81,7 +83,8 @@ const PersonalInformation = props => {
const isValid = isEmpty(errors)
const disabled =
(values.givenNames === initialValues.givenNames &&
values.surname === initialValues.surname) ||
values.surname === initialValues.surname &&
values.orcid === initialValues.orcid) ||
!isValid
return (
......@@ -106,6 +109,15 @@ const PersonalInformation = props => {
value={values.surname}
/>
<TextField
handleBlur={handleBlur}
handleChange={handleChange}
label="ORCID iD"
name="orcid"
touched={touched}
value={values.orcid}
/>
<Button disabled={disabled} primary type="submit">
Update
</Button>
......@@ -324,7 +336,7 @@ const UserProfile = props => {
} = props
if (loading) return <Loading />
const { givenNames, surname, username } = data
const { givenNames, surname, username, orcid } = data
return (
<Wrapper>
......@@ -332,6 +344,7 @@ const UserProfile = props => {
<PersonalInformation
givenNames={givenNames}
orcid={orcid}
surname={surname}
update={updatePersonalInformation}
/>
......
......@@ -18,6 +18,7 @@ extend type User {
displayName: String!
givenNames: String
surname: String
orcid: String
}
type Auth {
......@@ -37,11 +38,13 @@ type Auth {
extend input UserInput {
givenNames: String!
surname: String!
orcid: String
}
input UpdatePersonalInformationInput {
givenNames: String!
surname: String!
orcid: String
}
input UpdateUsernameInput {
......
......@@ -38,6 +38,14 @@ const currentUser = async (_, { input }, ctx) => {
const { createClientAuth } = auth
user.auth = await createClientAuth(userId)
const identity = await Identity.query().findOne({
isDefault: true,
userId: user.id,
})
user.orcid = identity.orcid
return user
}
......@@ -220,7 +228,7 @@ const resetPassword = async (_, { token, password }, ctx) => {
/* eslint-disable-next-line consistent-return */
const signUp = async (_, { input }, ctx) => {
const userInput = clone(input)
const { email, givenNames, password, surname, username } = userInput
const { email, givenNames, password, surname, username, orcid } = userInput
const usernameExists = await User.query().findOne({ username })
if (usernameExists) {
......@@ -297,6 +305,7 @@ const signUp = async (_, { input }, ctx) => {
isConfirmed: false,
isDefault: true,
userId: newUser.id,
orcid,
})
notify('identityVerification', {
......@@ -329,7 +338,14 @@ const updatePassword = async (_, { input }, ctx) => {
// NO AUTH
const updatePersonalInformation = async (_, { input }, ctx) => {
const userId = ctx.user
const { givenNames, surname } = input
const { givenNames, surname, orcid } = input
await Identity.query()
.patch({ orcid })
.where({
isDefault: true,
userId,
})
return User.query().patchAndFetchById(userId, {
givenNames,
......
......@@ -29,6 +29,7 @@ class Identity extends BaseModel {
isConfirmed: boolean,
confirmationToken: stringNullable,
confirmationTokenTimestamp: dateNullable,
orcid: stringNullable,
},
}
}
......
alter table only identities
add column orcid text
;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment