Last active
June 6, 2018 12:49
-
-
Save charlypoly/fd9d60b8f0d15c538c946d1243e41815 to your computer and use it in GitHub Desktop.
Apollo Form User demo
This file contains hidden or 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
import * as React from 'react'; | |
/* imports ... */ | |
import { client } from '../../core/apollo'; | |
const jsonSchema: JSONSchema6 = require('./core/apollo-form-json-schema.json'); | |
// this is common for the whole application, brang here for the example. | |
const AlineSidebarForm = configure<ApolloFormMutationNames>({ | |
client, | |
jsonSchema, | |
theme: alineSidebarTheme | |
}); | |
export default () => { | |
return ( | |
<Query | |
query={loadUserQueryDocument} | |
variables={{ id: ConnectedUserStorage.get() }} | |
fetchPolicy="network-only" | |
> | |
{(props: QueryResult<loadUserQuery>) => { | |
return ( | |
<AlineSidebarForm | |
title={t('Forms.UserForm.Panel.UpdateTitle')} | |
liveValidate={true} | |
config={{ | |
mutation: { | |
name: 'update_user', | |
document: updateUserMutationDocument, | |
variables: { id: ConnectedUserStorage.get() }, | |
}, | |
ignoreFields: ['user.platform_role_ids', 'user.space_role_ids'] | |
}} | |
data={props.data} | |
ui={{ | |
user: { | |
'ui:order': ['picture_path', '*'], | |
picture_path: { | |
'ui:widget': 'PictureWidget', | |
'ui:options': { transformations: 'h_200,w_200,r_max,c_fill' } | |
}, | |
language: { | |
'ui:widget': 'SelectStaticWidget', | |
'ui:options': { values: supportedLanguagesValues } | |
} | |
} | |
}} | |
onSave={(data: any) => { | |
if (data.user.language !== props.data!.user.language && | |
confirm(t('Forms.UserForm.LanguageChangedReload')) | |
) { | |
window.location.reload(); | |
} | |
}} | |
/> | |
); | |
}} | |
</Query> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment