Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,72 +1,87 @@
import React, { Fragment } from 'react';
import { Button, Form, FullGridSize, WebId } from "../../profile.style";
import { Button, Form, FullGridSize, WebId } from '../../profile.style';
import { Input } from '@util-components';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useTranslation } from 'react-i18next';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

export const FormUi = ({ onSubmit, formFields, mode, onCancel, onInputChange, updatedFields, webId }) => {

function getProfileValue(updatedFields: Object, item: Object) {
const currentKey = item.nodeBlank || item.property;
if (updatedFields[currentKey]) {
if (
updatedFields[currentKey].value ||
updatedFields[currentKey].value === ''
)
return updatedFields[currentKey].value;
export const FormUi = ({
onSubmit,
formFields,
mode,
onCancel,
onInputChange,
updatedFields,
webId,
}) => {
function getProfileValue(updatedFields: Object, item: Object) {
const currentKey = item.nodeBlank || item.property;
if (updatedFields[currentKey]) {
if (
updatedFields[currentKey].value ||
updatedFields[currentKey].value === ''
)
return updatedFields[currentKey].value;
}
return item.value || '';
}
return item.value || '';
}

return(
<Fragment>
<Form onSubmit={onSubmit}>
{formFields &&
formFields.map(item => (
<Input
key={item.label}
placeholder={item.label}
name={item.nodeBlank || item.property}
value={getProfileValue(updatedFields, item)}
onChange={onInputChange}
icon={item.icon}
readOnly={mode}
required={item.required}
data-nodeparenturi={item.nodeParentUri}
data-nodeblank={item.nodeBlank}
data-label={item.label}
data-icon={item.icon}
type={'text'}
/>
))}
<FullGridSize>
{!mode && (
<>
<Button
type='button'
onClick={onCancel}
className='ids-link-stroke ids-link-stroke--primary'
>
Cancel
</Button>
<Button
type='submit'
className='ids-link-filled ids-link-filled--primary'
>
Save
</Button>
</>
)}
</FullGridSize>
</Form>
{mode && (
<WebId>
<FontAwesomeIcon icon='id-card' />
<a href={webId} target='_blank' rel='noopener noreferrer'>
{webId}
</a>
</WebId>
)}
</Fragment>
);
}
const { t } = useTranslation();
return (
<Fragment>
<Form onSubmit={e => onSubmit(e, t('profile.updateSuccess'))}>
{formFields &&
formFields.map(item => (
<Input
key={item.label}
placeholder={item.label}
name={item.nodeBlank || item.property}
value={getProfileValue(updatedFields, item)}
onChange={onInputChange}
icon={item.icon}
readOnly={mode}
required={item.required}
data-nodeparenturi={item.nodeParentUri}
data-nodeblank={item.nodeBlank}
data-label={item.label}
data-icon={item.icon}
type={'text'}
onInvalid={e =>
e.target.setCustomValidity(
t('profile.nameRequired')
)
}
onInput={e => e.target.setCustomValidity('')}
/>
))}
<FullGridSize>
{!mode && (
<>
<Button
type="button"
onClick={onCancel}
className="ids-link-stroke ids-link-stroke--primary"
>
{t('profile.cancelBtn')}
</Button>
<Button
type="submit"
className="ids-link-filled ids-link-filled--primary"
>
{t('profile.saveBtn')}
</Button>
</>
)}
</FullGridSize>
</Form>
{mode && (
<WebId>
<FontAwesomeIcon icon="id-card" />
<a href={webId} target="_blank" rel="noopener noreferrer">
{webId}
</a>
</WebId>
)}
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ProfileForm extends Component {
* onSubmit will send all the updated fields to POD
* fields that was not updated will be not send it.
*/
onSubmit = async (e: Event) => {
onSubmit = async (e: Event, successMessage: String) => {
try {
e.preventDefault ();
let node;
Expand Down Expand Up @@ -140,10 +140,11 @@ export class ProfileForm extends Component {
formMode: true,
isLoading: false,
});

this.props.toastManager.add (['', 'Profile was updated successfully'], {
this.props.exitEditMode();
this.props.toastManager.add (['', successMessage], {
appearance: 'success',
});

} catch (error) {
this.props.toastManager.add (['Error', error.message], {
appearance: 'error',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,97 +1,108 @@
import React, { useState, useEffect } from 'react';
import data from "@solid/query-ldflex";
import data from '@solid/query-ldflex';
import { Uploader, useLiveUpdate } from '@inrupt/solid-react-components';
import { useTranslation } from "react-i18next";
import { useTranslation } from 'react-i18next';

import { ImageProfile } from '@components';

type Props = {
webId: String,
toastManager: String
webId: String,
toastManager: String,
};


export const Image = ({ webId, toastManager, defaultProfilePhoto }: Props) => {
const [image, setImage] = useState('');
const [image, setImage] = useState('');

const latestUpdate = useLiveUpdate();
const latestUpdate = useLiveUpdate();

const {t} = useTranslation();
const { t } = useTranslation();

useEffect( () => {
fetchPhoto();
}, [webId, latestUpdate]);
/**
* Fetch profile photo from card
*/
const fetchPhoto = async () => {
try {
if (webId) {
// We are fetching profile card document
const user = data.user;
/**
* We access to document node using a node name
* hasPhoto is a new context that ldflex doesn't having
* we need to add it manually.
* if you want to know more about context please go to:
* https://github.com/digitalbazaar/jsonld.js
*/
const image = await user.image || await user.vcard_hasPhoto;
useEffect(() => {
fetchPhoto();
}, [webId, latestUpdate]);
/**
* Fetch profile photo from card
*/
const fetchPhoto = async () => {
try {
if (webId) {
// We are fetching profile card document
const user = data.user;
/**
* We access to document node using a node name
* hasPhoto is a new context that ldflex doesn't having
* we need to add it manually.
* if you want to know more about context please go to:
* https://github.com/digitalbazaar/jsonld.js
*/
const image = (await user.image) || (await user.vcard_hasPhoto);

setImage(image && image.value);
}
} catch (error) {
toastManager.add (['Error', error.message], {
appearance: 'error',
});
}
};
/**
* updatedPhoto will update the photo url on vcard file
* this function will check if user has image or hasPhoto node if not
* will just update it, the idea is use image instead of hasPhoto
* @params{String} uri photo url
*/
const updatePhoto = async (uri: String) => {
try {
const {user} = data;
setImage(image && image.value);
}
} catch (error) {
toastManager.add(['Error', error.message], {
appearance: 'error',
});
}
};
/**
* updatedPhoto will update the photo url on vcard file
* this function will check if user has image or hasPhoto node if not
* will just update it, the idea is use image instead of hasPhoto
* @params{String} uri photo url
*/
const updatePhoto = async (uri: String) => {
try {
const { user } = data;

await user.image.set (uri)
await user.image.set(uri);

toastManager.add (['', t('profile.uploadSuccess')], {
appearance: 'success',
});
} catch (error) {
toastManager.add (['Error', error.message], {
appearance: 'error',
});
}
};
const limit = 2100000 ;
return (
<Uploader
{...{
fileBase: webId && webId.split('/card')[0],
limitFiles: 1,
limitSize: limit,
accept: 'png,jpeg,jpg',
errorsText: {
sizeLimit: t('profile.errors.sizeLimit', {limit: `${limit/1000000}Mbs`}),
unsupported: t('profile.errors.unsupported'),
maximumFiles: t('profile.errors.maximumFiles')
},
onError: error => {
if (error && error.statusText) {
toastManager.add(['', error.statusText], {
appearance: 'error'
toastManager.add(['', t('profile.uploadSuccess')], {
appearance: 'success',
});
} catch (error) {
toastManager.add(['Error', error.message], {
appearance: 'error',
});
}
},
onComplete: uploadedFiles => {
updatePhoto(uploadedFiles[uploadedFiles.length - 1].uri)
},
render: props => <ImageProfile {...{ ...props, webId, photo: image || defaultProfilePhoto }} />
}}
/>
);
}
};
const limit = 2100000;
return (
<Uploader
{...{
fileBase: webId && webId.split('/card')[0],
limitFiles: 1,
limitSize: limit,
accept: 'png,jpeg,jpg',
errorsText: {
sizeLimit: t('profile.errors.sizeLimit', {
limit: `${limit / 1000000}Mbs`,
}),
unsupported: t('profile.errors.unsupported'),
maximumFiles: t('profile.errors.maximumFiles'),
},
onError: error => {
if (error && error.statusText) {
toastManager.add(['', error.statusText], {
appearance: 'error',
});
}
},
onComplete: uploadedFiles => {
updatePhoto(uploadedFiles[uploadedFiles.length - 1].uri);
},
render: props => (
<ImageProfile
{...{
...props,
webId,
photo: image || defaultProfilePhoto,
text: t('profile.upload'),
uploadingText: t('profile.uploadingText'),
}}
/>
),
}}
/>
);
};
Loading