Create Appointment works
This commit is contained in:
@@ -4,6 +4,7 @@ import Header from './Header';
|
|||||||
import { Switch, Route } from 'react-router-dom';
|
import { Switch, Route } from 'react-router-dom';
|
||||||
// import ProductList from './ProductList';
|
// import ProductList from './ProductList';
|
||||||
import AppointmentList from './AppointmentList';
|
import AppointmentList from './AppointmentList';
|
||||||
|
import Events from './Events';
|
||||||
import Login from './Login';
|
import Login from './Login';
|
||||||
import Calendar from './Calendar';
|
import Calendar from './Calendar';
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ const App = () => {
|
|||||||
<Switch>
|
<Switch>
|
||||||
{/* <Route exact path="/" component={ProductList} /> */}
|
{/* <Route exact path="/" component={ProductList} /> */}
|
||||||
<Route exact path="/" component={AppointmentList} />
|
<Route exact path="/" component={AppointmentList} />
|
||||||
|
{/* <Route exact path="/events" component={Events} /> */}
|
||||||
<Route exact path="/create" component={CreateAppointment} />
|
<Route exact path="/create" component={CreateAppointment} />
|
||||||
<Route exact path="/login" component={Login} />
|
<Route exact path="/login" component={Login} />
|
||||||
<Route exact path="/calendar" component={Calendar} />
|
<Route exact path="/calendar" component={Calendar} />
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const Appointment = (props) => {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<b>{appointment.title}</b> starts at {appointment.timeStart}, ends at {appointment.timeEnd}. It is described as "{appointment.description}"
|
<b>{appointment.title}</b> starts at {appointment.start}, ends at {appointment.end}. It is described as "{appointment.description}"
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ export const APPOINTMENTS_QUERY = gql`
|
|||||||
allAppointments{
|
allAppointments{
|
||||||
title
|
title
|
||||||
description
|
description
|
||||||
timeStart
|
start
|
||||||
timeEnd
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@@ -17,9 +17,8 @@ const AppointmentList = () => {
|
|||||||
|
|
||||||
const { data } = useQuery(APPOINTMENTS_QUERY);
|
const { data } = useQuery(APPOINTMENTS_QUERY);
|
||||||
|
|
||||||
console.log("Data:", data);
|
|
||||||
|
|
||||||
if (data !== undefined) {
|
if (data !== undefined) {
|
||||||
|
console.log(data.allAppointments);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import dayGridPlugin from '@fullcalendar/daygrid'
|
|||||||
import interactionPlugin from "@fullcalendar/interaction";
|
import interactionPlugin from "@fullcalendar/interaction";
|
||||||
import { useQuery, gql } from '@apollo/client';
|
import { useQuery, gql } from '@apollo/client';
|
||||||
import { APPOINTMENTS_QUERY } from './AppointmentList';
|
import { APPOINTMENTS_QUERY } from './AppointmentList';
|
||||||
|
import Events from './Events'
|
||||||
|
|
||||||
// function renderEventContent() {
|
// function renderEventContent() {
|
||||||
// const { loading, error, data } = useQuery(APPOINTMENTS_QUERY, {
|
// const { loading, error, data } = useQuery(APPOINTMENTS_QUERY, {
|
||||||
@@ -16,14 +17,34 @@ import { APPOINTMENTS_QUERY } from './AppointmentList';
|
|||||||
// <b>{eventInfo.timeText}</b>
|
// <b>{eventInfo.timeText}</b>
|
||||||
// <i>{eventInfo.event.title}</i>
|
// <i>{eventInfo.event.title}</i>
|
||||||
// </>
|
// </>
|
||||||
// )
|
// )s
|
||||||
// // return <h1>Hello {data.greeting.message}!</h1>;
|
// // return <h1>Hello {data.greeting.message}!</h1>;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
export default class Calendar extends React.Component {
|
export default class Calendar extends React.Component {
|
||||||
|
|
||||||
handleDateClick = (arg) => { // bind with an arrow function
|
// formatEvents() {
|
||||||
alert(arg.dateStr)
|
|
||||||
|
// // const { data } = useQuery(APPOINTMENTS_QUERY);
|
||||||
|
// return this.props.appointments.map(appointment => {
|
||||||
|
// const { title, end, start } = appointment
|
||||||
|
|
||||||
|
// let startTime = new Date(start)
|
||||||
|
// let endTime = new Date(end)
|
||||||
|
|
||||||
|
// return {
|
||||||
|
// title,
|
||||||
|
// start: startTime,
|
||||||
|
// end: endTime,
|
||||||
|
// extendedProps: { ...appointment }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
|
handleDateClick = (arg) => {
|
||||||
|
arg.jsEvent.preventDefault();
|
||||||
|
alert(arg.event.extendedProps.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -34,10 +55,20 @@ export default class Calendar extends React.Component {
|
|||||||
initialView="dayGridMonth"
|
initialView="dayGridMonth"
|
||||||
weekends={true}
|
weekends={true}
|
||||||
eventClick={this.handleDateClick}
|
eventClick={this.handleDateClick}
|
||||||
// eventContent={renderEventContent}
|
events={this.formatEvents}
|
||||||
events={[
|
events={[
|
||||||
{ title: 'event 1', start: '2021-01-03 13:45:00', end: '2021-01-03 16:15:00' },
|
{
|
||||||
{ title: 'event 2', start: '2021-01-05 09:00:00', end: '2021-01-03 10:30:00' }
|
"title": "fyufyjd",
|
||||||
|
"description": "kr7y i7r77tk ruru",
|
||||||
|
"start": "2021-01-05T12:45:51.000Z",
|
||||||
|
"end": "2021-01-05T17:00:00.000Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "dyt",
|
||||||
|
"description": "uudtkdjtdtukduk",
|
||||||
|
"start": "2021-01-04T17:45:51.000Z",
|
||||||
|
"end": "2021-01-04T20:00:00.000Z"
|
||||||
|
}
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,15 +10,14 @@ const CREATE_APPOINTMENT_MUTATION = gql`
|
|||||||
mutation CreateAppointmentMutation(
|
mutation CreateAppointmentMutation(
|
||||||
$title: String!
|
$title: String!
|
||||||
$description: String!
|
$description: String!
|
||||||
$timeStart: String!
|
$start: String!
|
||||||
$timeEnd: String!
|
$end: String!
|
||||||
) {
|
) {
|
||||||
createAppointment(title: $title, description: $description, timeStart: $timeStart, timeEnd: $timeEnd) {
|
createAppointment(title: $title, description: $description, start: $start, end: $end) {
|
||||||
id
|
|
||||||
title
|
title
|
||||||
description
|
description
|
||||||
timeStart
|
start
|
||||||
timeEnd
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@@ -29,46 +28,46 @@ const CreateAppointment = () => {
|
|||||||
const [formState, setFormState] = useState({
|
const [formState, setFormState] = useState({
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
timeStart: '',
|
start: '',
|
||||||
timeEnd: ''
|
end: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
const [createAppointment] = useMutation(CREATE_APPOINTMENT_MUTATION, {
|
const [createAppointment] = useMutation(CREATE_APPOINTMENT_MUTATION, {
|
||||||
variables: {
|
variables: {
|
||||||
title: formState.title,
|
title: formState.title,
|
||||||
description: formState.description,
|
description: formState.description,
|
||||||
timeStart: formState.timeStart,
|
start: formState.start,
|
||||||
timeEnd: formState.timeEnd
|
end: formState.end
|
||||||
},
|
},
|
||||||
update: (cache, { data: { createAppointment } }) => {
|
// update: (cache, { data: { createAppointment } }) => {
|
||||||
const take = APPOINTMENTS_PER_PAGE;
|
// const take = APPOINTMENTS_PER_PAGE;
|
||||||
const skip = 0;
|
// const skip = 0;
|
||||||
const orderBy = { createdAt: 'desc' };
|
// const orderBy = { createdAt: 'desc' };
|
||||||
|
|
||||||
const data = cache.readQuery({
|
// const data = cache.readQuery({
|
||||||
query: APPOINTMENTS_QUERY,
|
// query: APPOINTMENTS_QUERY,
|
||||||
variables: {
|
// variables: {
|
||||||
take,
|
// take,
|
||||||
skip,
|
// skip,
|
||||||
orderBy
|
// orderBy
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
cache.writeQuery({
|
// cache.writeQuery({
|
||||||
query: APPOINTMENTS_QUERY,
|
// query: APPOINTMENTS_QUERY,
|
||||||
data: {
|
// data: {
|
||||||
allAppointments: {
|
// allAppointments: {
|
||||||
appointments: [createAppointment, ...data.allAppointments.appointments]
|
// appointments: [createAppointment, ...data.allAppointments]
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
variables: {
|
// variables: {
|
||||||
take,
|
// take,
|
||||||
skip,
|
// skip,
|
||||||
orderBy
|
// orderBy
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
onCompleted: () => history.push('/new/1')
|
onCompleted: () => history.push('/')
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -106,38 +105,26 @@ const CreateAppointment = () => {
|
|||||||
/>
|
/>
|
||||||
<Datetime
|
<Datetime
|
||||||
className="mb2"
|
className="mb2"
|
||||||
value={formState.timeStart}
|
value={formState.start}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setFormState({
|
setFormState({
|
||||||
...formState,
|
...formState,
|
||||||
timeStart: e
|
start: e
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Datetime
|
<Datetime
|
||||||
className="mb2"
|
className="mb2"
|
||||||
value={formState.timeStart}
|
value={formState.end}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
setFormState({
|
setFormState({
|
||||||
...formState,
|
...formState,
|
||||||
timeEnd: e
|
end: e
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{/* <input
|
|
||||||
className="mb2"
|
|
||||||
value={formState.timeEnd}
|
|
||||||
onChange={(e) =>
|
|
||||||
setFormState({
|
|
||||||
...formState,
|
|
||||||
timeStart: e.target.value
|
|
||||||
})
|
|
||||||
}
|
|
||||||
type="text"
|
|
||||||
placeholder="Input end time"
|
|
||||||
/> */}
|
|
||||||
</div>
|
</div>
|
||||||
<button type="submit">Submit</button>
|
<button type="submit">Create appointment</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
17
client/src/components/EventType.js
Normal file
17
client/src/components/EventType.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { useQuery } from '@apollo/react-hooks';
|
||||||
|
function EventType({ types }) {
|
||||||
|
const { loading, error, data } = useQuery(GET_EVENT_TYPES);
|
||||||
|
|
||||||
|
if (loading) return 'Loading...';
|
||||||
|
if (error) return `Error! ${error.message}`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<select name="type" onChange={onTypeSelected}>
|
||||||
|
{data.types.map(type => (
|
||||||
|
<option key={type.id} value={type.name}>
|
||||||
|
{type.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
);
|
||||||
|
}
|
||||||
36
client/src/components/Events.js
Normal file
36
client/src/components/Events.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useQuery, gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const APPOINTMENTS_QUERY = gql`
|
||||||
|
{
|
||||||
|
allAppointments{
|
||||||
|
title
|
||||||
|
description
|
||||||
|
start
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
var EventsList = [];
|
||||||
|
|
||||||
|
const Events = () => {
|
||||||
|
|
||||||
|
const { data } = useQuery(APPOINTMENTS_QUERY);
|
||||||
|
|
||||||
|
|
||||||
|
// if (data !== undefined) {
|
||||||
|
console.log("Data:", data.allAppointments);
|
||||||
|
EventsList = data.allAppointments;
|
||||||
|
return (
|
||||||
|
EventsList
|
||||||
|
);
|
||||||
|
// } else {
|
||||||
|
// return (
|
||||||
|
// EventsList
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EventsList;
|
||||||
@@ -9,11 +9,11 @@ const AppointmentSchema = new Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
required: false
|
required: false
|
||||||
},
|
},
|
||||||
timeStart: {
|
start: {
|
||||||
type: Date,
|
type: Date,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
timeEnd: {
|
end: {
|
||||||
type: Date,
|
type: Date,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -97,10 +97,8 @@ export const resolvers = {
|
|||||||
// };
|
// };
|
||||||
// },
|
// },
|
||||||
|
|
||||||
async createAppointment(root, {
|
async createAppointment(parent, args, context, info) {
|
||||||
input
|
return await Appointment.create(args);
|
||||||
}) {
|
|
||||||
return await Appointment.create(input);
|
|
||||||
},
|
},
|
||||||
async updateAppointment(root, {
|
async updateAppointment(root, {
|
||||||
_id,
|
_id,
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ type Feed {
|
|||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
createAppointment(
|
createAppointment(
|
||||||
input: AppointmentInput
|
title: String!
|
||||||
|
description: String!
|
||||||
|
start: String!
|
||||||
|
end: String!
|
||||||
|
# input: AppointmentInput
|
||||||
): Appointment!
|
): Appointment!
|
||||||
updateAppointment(
|
updateAppointment(
|
||||||
_id: ID!,
|
_id: ID!,
|
||||||
@@ -82,8 +86,8 @@ type Appointment {
|
|||||||
_id: ID!
|
_id: ID!
|
||||||
title: String!
|
title: String!
|
||||||
description: String!
|
description: String!
|
||||||
timeStart: Time!
|
start: Time!
|
||||||
timeEnd: Time!
|
end: Time!
|
||||||
deleted: Boolean
|
deleted: Boolean
|
||||||
# createdBy: User
|
# createdBy: User
|
||||||
# follows: [Follow!]!
|
# follows: [Follow!]!
|
||||||
@@ -92,8 +96,8 @@ type Appointment {
|
|||||||
input AppointmentInput {
|
input AppointmentInput {
|
||||||
title: String!
|
title: String!
|
||||||
description: String!
|
description: String!
|
||||||
timeStart: Time!
|
start: Time!
|
||||||
timeEnd: Time!
|
end: Time!
|
||||||
}
|
}
|
||||||
input AppointmentOrderByInput {
|
input AppointmentOrderByInput {
|
||||||
description: Sort
|
description: Sort
|
||||||
|
|||||||
Reference in New Issue
Block a user