This file contains 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
const ProfileFormSchema = Yup.object().shape({ | |
name: Yup.string().required("Required"), | |
age: Yup.number(), | |
phoneNumber: Yup.string() | |
.matches(phoneRegExp, "Phone is not valid") | |
.required("Required"), | |
}); |
This file contains 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
function ProfileForm(props: Props) { | |
const classes = useStyles(); | |
const { profile } = props; | |
const [updateProfile] = useMutation<UpdateProfile, UpdateProfileVariables>( | |
UPDATE_PROFILE_INFORMATION | |
); | |
return ( | |
<Grid container item spacing={2} xs={12} sm={6}> | |
<Typography variant="h5" gutterBottom> | |
Enter the user's profile information |
This file contains 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
// @generated | |
// This file was automatically generated and should not be edited. | |
// ==================================================== | |
// GraphQL fragment: ProfileData | |
// ==================================================== | |
export interface ProfileData_business { | |
__typename: "Business"; | |
/** |
This file contains 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
const fragments = { | |
data: gql` | |
fragment ProfileData on Profile { | |
name | |
age | |
phoneNumber | |
} | |
` | |
}; |
This file contains 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 React from "react"; | |
import { useParams } from "react-router-dom"; | |
import { gql, useQuery } from "@apollo/client"; | |
import Container from "@material-ui/core/Container"; | |
import Typography from "@material-ui/core/Typography"; | |
import ProfileForm from "./ProfileForm"; | |
const ProfileFormsQuery = gql` | |
query ProfileForms { | |
profile(pk: $pk) { |
This file contains 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
>>> from core.models import Business | |
>>> from core.models import Profile | |
>>> from core.schema import ProfileForm | |
>>> b = Business.objects.first() | |
>>> data = {"phone_number": "+15555555555"} | |
>>> f = ProfileForm(data=data) | |
>>> f.is_valid() | |
False | |
>>> f.errors | |
{'age': ['This field is required.'], 'business': ['This field is required.']} |
This file contains 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
from django import forms | |
class ProfileForm(forms.ModelForm): | |
class Meta: | |
model = core.models.Profile | |
fields = ['name', 'age', 'phone_number', 'business'] |
This file contains 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 graphene | |
from graphene_django.types import DjangoObjectType | |
import core.models | |
class Profile(DjangoObjectType): | |
class Meta: | |
model = core.models.Profile |
This file contains 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
from django.db import models | |
class Business(models.Model): | |
NORTH_AMERICA = "North America" | |
ASIA = "Asia" | |
AFRICA = "Africa" | |
SOUTH_AMERICA = "South America" | |
AUSTRALIA = "Australia" | |
LOCATION_CHOICES = ( |
This file contains 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 React, {Component} from 'react'; | |
import { Admin, Resource } from 'react-admin'; | |
import buildGraphQLProvider from 'ra-data-graphql'; | |
import ApolloClient from 'apollo-boost'; | |
import { buildQuery } from './buildQuery'; | |
import { uri } from './config'; | |
const client = ApolloClient({ uri }); |
NewerOlder