Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds chips to push roles #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/modules/profile/components/CreateUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mutation createUser(
$password: String!,
$password_confirmation: String!,
$profile_picture_b64: String,
$role: String!
$role: [String!]!
) {
createUser(
first_name: $first_name,
Expand All @@ -47,7 +47,7 @@ interface IVariables {
email: string,
password?: string,
password_confirmation?: string,
role: string,
role: string[],
profile_picture_b64: string
}

Expand All @@ -60,7 +60,7 @@ const initialUserState = {
password: "Hello",
password_confirmation: "",
isCreate: true,
role: "",
role: [],
profile_pic_url: "",
profile_picture_b64: ""
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/profile/components/EditUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mutation updateUser(
$last_name: String!,
$email: String!,
$profile_picture_b64: String,
$role: String,
$role: [String!]!,
$id: ID!,
) {
updateUser(
Expand All @@ -70,7 +70,7 @@ interface IVariables {
first_name: string,
last_name: string,
email: string,
role: string,
role: string[],
profile_picture_b64: string
}

Expand Down Expand Up @@ -122,7 +122,7 @@ const EditUserUnconnected: React.FunctionComponent<any> = ({ slug }) => {
email: data.userBySlug!.email,
profile_pic_url: data.userBySlug!.profile_pic_url,
password: "",
role: "",
role: [],
isCreate: false,
profile_picture_b64: ""
}}
Expand Down
13 changes: 6 additions & 7 deletions src/modules/profile/components/UserFormBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ interface IState {
email: string,
password: string,
profile_pic_url: string,
role: string,
role: string[],
isCreate: boolean,
profile_picture_b64: string
profile_picture_b64: string,
}

interface IProps {
Expand All @@ -31,7 +31,6 @@ export class UserFormBase extends React.Component<IProps, IState> {
super(props);
this.state = props.initialState;
}

public render() {
let password = this.state.isCreate &&
<div>
Expand Down Expand Up @@ -74,9 +73,9 @@ export class UserFormBase extends React.Component<IProps, IState> {
{password}
<RoleField
role={this.state.role}
onChange={this.handleRoleChange}
onInteraction={this.handleRoleChange}
label="Role"
required={this.state.isCreate}
required={true}
/>
<br/>
<img
Expand All @@ -91,7 +90,7 @@ export class UserFormBase extends React.Component<IProps, IState> {
onPFPURLChange={this.handlePFPURLChange}
/>
</div>
<Button>
<Button type='submit'>
{this.props.postLabel}
</Button>
</form>
Expand All @@ -118,7 +117,7 @@ export class UserFormBase extends React.Component<IProps, IState> {
password
})
}
private handleRoleChange = (role: string) => {
private handleRoleChange = (role: string[]) => {
this.setState({
role
})
Expand Down
102 changes: 73 additions & 29 deletions src/modules/profile/components/helpers/RoleField.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,77 @@
import * as React from 'react';
import * as React from 'react';

import { Select } from '@rmwc/select';
import {Chip} from '@rmwc/chip';
import {ChipIcon} from '@rmwc/chip';
import {ChipSet} from '@rmwc/chip';

interface IProps {
onInteraction: (s: string[]) => void,
error?: string,
label: string,
required:boolean,
role: String[]
}

interface IProps {
role: string,
onChange: (s: string) => void,
error?: string,
label: string,
required?: boolean,
}
export const RoleField: React.FunctionComponent<IProps> = ({
role = [],
}) => {

export const RoleField: React.SFC<IProps> = ({
role,
onChange,
error,
label,
required
}) => {
return (
<Select
className="UserField"
value={role}
onChange={(e: React.FormEvent<HTMLInputElement>) => onChange(e.currentTarget.value)}
label={label}
enhanced
outlined
options={["Contributor", "Illustrator", "Photographer"]}
required={required}
/>
);
};
function select(value: any){
toggleSelected(value);
arrayEdit(value);
};
function arrayEdit(this: any, roles: string){
if(role.includes(roles)){
const index = role.indexOf(roles);
delete role[index]
} else{
role.push(roles);
}
}
const [selected, setSelected] = React.useState({
Contributor: false,
Illustrator: false,
Photographer: false
});

const toggleSelected = (key: keyof typeof selected) =>
setSelected({
...selected,
[key]: !selected[key]
});

return (
<ChipSet
filter
style={{marginLeft: "1.5%", marginTop:"0.5%"}}
>
<Chip
type='button'
icon="insert_comment"
selected={selected.Contributor}
checkmark
onInteraction={() => select('Contributor')}
label="Contributor"
key="contributor"
/>
<Chip
type='button'
icon="palette"
selected={selected.Illustrator}
checkmark
onInteraction={() => select('Illustrator')}
label="Illustrator"
key="illustrator"
/>
<Chip
type='button'
icon="camera_alt"
selected={selected.Photographer}
checkmark
onInteraction={() => select("Photographer")}
label="Photographer"
key='photographer'
/>
</ChipSet>
);
};