|  | @@ -1,32 +1,36 @@
 | 
											
												
													
														|  | -import { ChangeEvent } from 'react'
 |  | 
 | 
											
												
													
														|  | -import { useTrainingTypesQuery } from '../../gql'
 |  | 
 | 
											
												
													
														|  | 
 |  | +import { ChangeEvent } from "react";
 | 
											
												
													
														|  | 
 |  | +import { useTrainingTypesQuery } from "../../gql";
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  interface ITrainingTypeSelector {
 |  |  interface ITrainingTypeSelector {
 | 
											
												
													
														|  | -  value: { connect: { id: string } } | undefined
 |  | 
 | 
											
												
													
														|  | -  label?: string
 |  | 
 | 
											
												
													
														|  | -  name?: string
 |  | 
 | 
											
												
													
														|  | -  onChange: (event: ChangeEvent<HTMLSelectElement> | NestedEvent) => void
 |  | 
 | 
											
												
													
														|  | 
 |  | +  value: { connect: { id: string } } | undefined;
 | 
											
												
													
														|  | 
 |  | +  label?: string;
 | 
											
												
													
														|  | 
 |  | +  name?: string;
 | 
											
												
													
														|  | 
 |  | +  onChange: (event: ChangeEvent<HTMLSelectElement> | NestedEvent) => void;
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  const TrainingTypeSelector = ({
 |  |  const TrainingTypeSelector = ({
 | 
											
												
													
														|  |    onChange,
 |  |    onChange,
 | 
											
												
													
														|  |    value,
 |  |    value,
 | 
											
												
													
														|  | -  name = 'type',
 |  | 
 | 
											
												
													
														|  | -  label = 'Training type',
 |  | 
 | 
											
												
													
														|  | 
 |  | +  name = "type",
 | 
											
												
													
														|  | 
 |  | +  label = "Training type",
 | 
											
												
													
														|  |    ...props
 |  |    ...props
 | 
											
												
													
														|  |  }: ITrainingTypeSelector) => {
 |  |  }: ITrainingTypeSelector) => {
 | 
											
												
													
														|  | -  const trainingTypes = useTrainingTypesQuery()
 |  | 
 | 
											
												
													
														|  | -  const id = value && value.connect.id
 |  | 
 | 
											
												
													
														|  | 
 |  | +  const trainingTypes = useTrainingTypesQuery();
 | 
											
												
													
														|  | 
 |  | +  const id = value && value.connect.id;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -  if (trainingTypes.data && !value) {
 |  | 
 | 
											
												
													
														|  | -    const id = trainingTypes.data.trainingTypes[0].id
 |  | 
 | 
											
												
													
														|  | 
 |  | +  if (
 | 
											
												
													
														|  | 
 |  | +    trainingTypes.data &&
 | 
											
												
													
														|  | 
 |  | +    trainingTypes.data.trainingTypes.length > 0 &&
 | 
											
												
													
														|  | 
 |  | +    !value
 | 
											
												
													
														|  | 
 |  | +  ) {
 | 
											
												
													
														|  | 
 |  | +    const id = trainingTypes.data.trainingTypes[0].id;
 | 
											
												
													
														|  |      onChange({
 |  |      onChange({
 | 
											
												
													
														|  |        target: {
 |  |        target: {
 | 
											
												
													
														|  | -        type: 'custom',
 |  | 
 | 
											
												
													
														|  | 
 |  | +        type: "custom",
 | 
											
												
													
														|  |          value: { connect: { id } },
 |  |          value: { connect: { id } },
 | 
											
												
													
														|  |          name
 |  |          name
 | 
											
												
													
														|  |        }
 |  |        }
 | 
											
												
													
														|  | -    })
 |  | 
 | 
											
												
													
														|  | 
 |  | +    });
 | 
											
												
													
														|  |    }
 |  |    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |    return (
 |  |    return (
 | 
											
										
											
												
													
														|  | @@ -39,17 +43,17 @@ const TrainingTypeSelector = ({
 | 
											
												
													
														|  |          onChange={event => {
 |  |          onChange={event => {
 | 
											
												
													
														|  |            const copy: NestedEvent = {
 |  |            const copy: NestedEvent = {
 | 
											
												
													
														|  |              target: {
 |  |              target: {
 | 
											
												
													
														|  | -              type: 'custom',
 |  | 
 | 
											
												
													
														|  | 
 |  | +              type: "custom",
 | 
											
												
													
														|  |                value: { connect: { id: event.target.value } },
 |  |                value: { connect: { id: event.target.value } },
 | 
											
												
													
														|  |                name
 |  |                name
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | -          }
 |  | 
 | 
											
												
													
														|  | -          onChange(copy)
 |  | 
 | 
											
												
													
														|  | 
 |  | +          };
 | 
											
												
													
														|  | 
 |  | +          onChange(copy);
 | 
											
												
													
														|  |          }}
 |  |          }}
 | 
											
												
													
														|  |          {...props}
 |  |          {...props}
 | 
											
												
													
														|  |        >
 |  |        >
 | 
											
												
													
														|  | -        {trainingTypes.loading && 'loading training types...'}
 |  | 
 | 
											
												
													
														|  | -        {trainingTypes.error && 'error loading training types'}
 |  | 
 | 
											
												
													
														|  | 
 |  | +        {trainingTypes.loading && "loading training types..."}
 | 
											
												
													
														|  | 
 |  | +        {trainingTypes.error && "error loading training types"}
 | 
											
												
													
														|  |          {trainingTypes.data &&
 |  |          {trainingTypes.data &&
 | 
											
												
													
														|  |            trainingTypes.data.trainingTypes.map(trainingType => (
 |  |            trainingTypes.data.trainingTypes.map(trainingType => (
 | 
											
												
													
														|  |              <option
 |  |              <option
 | 
											
										
											
												
													
														|  | @@ -62,14 +66,14 @@ const TrainingTypeSelector = ({
 | 
											
												
													
														|  |            ))}
 |  |            ))}
 | 
											
												
													
														|  |        </select>
 |  |        </select>
 | 
											
												
													
														|  |        <button
 |  |        <button
 | 
											
												
													
														|  | -        type='button'
 |  | 
 | 
											
												
													
														|  | 
 |  | +        type="button"
 | 
											
												
													
														|  |          onClick={event => {
 |  |          onClick={event => {
 | 
											
												
													
														|  | -          event.preventDefault()
 |  | 
 | 
											
												
													
														|  | 
 |  | +          event.preventDefault();
 | 
											
												
													
														|  |          }}
 |  |          }}
 | 
											
												
													
														|  |        >
 |  |        >
 | 
											
												
													
														|  |          Add type
 |  |          Add type
 | 
											
												
													
														|  |        </button>
 |  |        </button>
 | 
											
												
													
														|  |      </>
 |  |      </>
 | 
											
												
													
														|  | -  )
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -export default TrainingTypeSelector
 |  | 
 | 
											
												
													
														|  | 
 |  | +  );
 | 
											
												
													
														|  | 
 |  | +};
 | 
											
												
													
														|  | 
 |  | +export default TrainingTypeSelector;
 |