Adding a key selector

This commit is contained in:
Unknown committed 2019-02-21 12:59:03 +01:00
1 parent 048aa14722
commit be24f38ded
4 files changed
+99 -42

No files matched your search

+65 -36
View File
@@ -16,8 +16,23 @@ import { hostedEventsCalls } from '../../GraphQL/Calls/index';
import { toLocalTime } from '../../utils';
class Event extends React.Component {
constructor() {
super();
this.state = {
keyId: '',
participantId: '',
botId: '',
};
}
render() {
const { classes, event, enrollable = false } = this.props;
const { keyId, participantId, botId } = this.state;
const {
classes,
event,
availableKey = [],
enrollable = false,
} = this.props;
const {
id,
title,
@@ -65,50 +80,64 @@ class Event extends React.Component {
<Typography gutterBottom>You are participating as : { participatingAs.map(team => `${team.name}, `) } </Typography>
</Grid>
<Grid item className={classes.buttonGrid}>
{ enrollable
{ enrollable && fbs.length
? <Mutation mutation={hostedEventsCalls.REGISTER_EVENT}
update={() => {
window.location.reload();
}}
>
{enrollToEvent => (
<Select
value={''}
onChange={(val) => {
enrollToEvent({
variables: {
eventId: id,
<React.Fragment>
<Select
value={`${participantId}|${botId}`}
onChange={(val) => {
this.setState({
participantId: val.target.value.split('|')[0],
botId: val.target.value.split('|')[1],
});
}}
name='bot'
displayEmpty
className={classes.selectEmpty}
>
<MenuItem value='|' disabled>
Enroll as :
</MenuItem>
{ fbs.map(finb => <MenuItem
key={finb.value}
value={finb.value}>{finb.text}</MenuItem>) }
</Select>
<Select
value={keyId}
onChange={(val) => { this.setState({ keyId: val.target.value }); }}
name='key'
displayEmpty
className={classes.selectEmpty}
>
<MenuItem value='' disabled>
Select key
</MenuItem>
{ availableKey.map(akey => <MenuItem
key={akey.id}
value={akey.id}>{akey.key}</MenuItem>) }
</Select>
<Button
className={classes.buttonList}
variant='outlined'
color='secondary'
size='small'
onClick={() => enrollToEvent({
variables: {
eventId: id,
keyId,
participantId,
botId,
},
});
}}
name='bot'
displayEmpty
className={classes.selectEmpty}
>
<MenuItem value='' disabled>
Enroll as :
</MenuItem>
{ fbs.map(finb => <MenuItem
key={finb.value}
value={finb.value}>{finb.text}</MenuItem>) }
</Select>
// <Button
// className={classes.buttonList}
// variant='outlined'
// color='secondary'
// size='small'
// onClick={() => enrollToEvent({
// variables: {
// eventId: id,
// participantId: 'test',
// botId: 'test',
// },
// })}
// >
// Enroll
// </Button>
})}
>
Enroll
</Button>
</React.Fragment>
)}
</Mutation>
: ''
+2 -2
View File
@@ -9,10 +9,10 @@ import Event from '../Event';
class Future extends React.Component {
render() {
const { classes } = this.props;
const { Events } = this.props;
const { Events, AKey } = this.props;
const events = Events.map((event, index) => (
<Event key={index} event={event} enrollable={true} />
<Event key={index} event={event} availableKey={AKey} enrollable={true} />
));
return (
<div className='container'>
+2 -2
View File
@@ -107,7 +107,7 @@ class Search extends React.Component {
}}
</Query>
<Query
query={hostedEventsCalls.EVENTS_EVENTSBYHOST}
query={hostedEventsCalls.EVENTS_EVENT_AND_AKEY}
variables={{ minStartDate: time.now }}
>
{({ loading, error, data }) => {
@@ -115,7 +115,7 @@ class Search extends React.Component {
if (error) return `Error! ${error.message}`;
return (
<React.Fragment>
{value === 1 && <TabContainer><Future Events={data.events_Events} /></TabContainer>}
{value === 1 && <TabContainer><Future Events={data.events_Events} AKey={data.keyVault_AvailableKeys} /></TabContainer>}
</React.Fragment>
);
}}
+30 -2
View File
@@ -42,6 +42,33 @@ const EVENTS_EVENTSBYHOST = gql`
${eventFullInfo}
`;
const EVENTS_EVENT_AND_AKEY = gql`
query Events_Events(
$hostId: String,
$state: events_EventStateEnum,
$minStartDate: Int,
$maxStartDate: Int,
$minEndDate: Int,
$maxEndDate: Int
){
events_Events(
hostId: $hostId,
state: $state,
minStartDate: $minStartDate,
maxStartDate: $maxStartDate,
minEndDate: $minEndDate,
maxEndDate: $maxEndDate
) {
...EventFullInfo
}
keyVault_AvailableKeys{
id
key
}
}
${eventFullInfo}
`;
const EVENTS_PUBLISHEVENT = gql`
mutation Events_ChangeEventState($eventId: ID!, $state: events_EventStateEnum) {
events_ChangeEventState(eventId: $eventId, state: $state) {
@@ -52,10 +79,10 @@ const EVENTS_PUBLISHEVENT = gql`
`;
const REGISTER_EVENT = gql`
mutation Events_RegisterToEvent($eventId: ID!, $participantId: String!, $botId: String!) {
mutation Events_RegisterToEvent($eventId: ID!, $keyId: String!, $participantId: String!, $botId: String!) {
events_RegisterToEvent(
eventId: $eventId
participant: { participantId: $participantId, botId: $botId }
participant: { keyId: $keyId, participantId: $participantId, botId: $botId }
) {
...EventFullInfo
}
@@ -67,6 +94,7 @@ export default {
EVENTS_CREATEEVENT,
EVENTS_EDITEVENT,
EVENTS_EVENTSBYHOST,
EVENTS_EVENT_AND_AKEY,
EVENTS_PUBLISHEVENT,
REGISTER_EVENT,
};