Add leader to year group after create
This commit is contained in:
parent
817095cc3f
commit
25355be9ff
@ -69,7 +69,7 @@ def create_project_supervisor(data: dict) -> dict:
|
||||
db.session.add(project_supervisor)
|
||||
db.session.commit()
|
||||
|
||||
return {"message": "Project Supervisor was created!"}
|
||||
return {"message": "Project Supervisor was created!", "id": project_supervisor.id}
|
||||
|
||||
|
||||
@bp.get("/<int:id>/detail")
|
||||
|
@ -52,7 +52,7 @@ class StudentEditSchema(ma.Schema):
|
||||
|
||||
class MessageSchema(ma.Schema):
|
||||
message = fields.Str(required=True)
|
||||
|
||||
id = fields.Str(required=False)
|
||||
|
||||
class FileSchema(ma.Schema):
|
||||
file = fields.Raw(type='file', required=True)
|
||||
|
@ -12,7 +12,7 @@ export interface Leader {
|
||||
first_name: string
|
||||
last_name: string
|
||||
email: string
|
||||
limit_group: number
|
||||
limit_group?: number
|
||||
count_groups: number
|
||||
}
|
||||
|
||||
@ -36,3 +36,13 @@ export const createLeader = (payload: Partial<Leader>) =>
|
||||
|
||||
export const deleteLeader = (id: number) =>
|
||||
axiosInstance.delete(`coordinator/project_supervisor/${id}/`)
|
||||
|
||||
export const addLeaderToGroup = (
|
||||
id: number,
|
||||
year_group_id: number,
|
||||
payload: { limit_group: number },
|
||||
) =>
|
||||
axiosInstance.post(
|
||||
`coordinator/project_supervisor/${id}/year-group/${year_group_id}`,
|
||||
payload,
|
||||
)
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { useMutation } from 'react-query'
|
||||
import { createLeader, Leader } from '../../api/leaders'
|
||||
import useLocalStorageState from 'use-local-storage-state'
|
||||
import { addLeaderToGroup, createLeader, Leader } from '../../api/leaders'
|
||||
import InputError from '../../components/InputError'
|
||||
|
||||
const AddLeader = () => {
|
||||
@ -11,18 +12,35 @@ const AddLeader = () => {
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
reset,
|
||||
getValues,
|
||||
} = useForm<Leader>()
|
||||
const [yearGroupId] = useLocalStorageState('yearGroupId')
|
||||
|
||||
const { mutate: mutateCreateLeader } = useMutation(
|
||||
'createLeader',
|
||||
(payload: Leader) => createLeader(payload),
|
||||
(payload: Leader) => {
|
||||
delete payload.limit_group
|
||||
return createLeader(payload)
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
reset()
|
||||
onSuccess: (data) => {
|
||||
setIsAlertVisible(true)
|
||||
mutateAddToYearGroup({
|
||||
id: data?.data?.id,
|
||||
year_group_id: Number(yearGroupId),
|
||||
limit_group: getValues('limit_group') ?? 0,
|
||||
})
|
||||
reset()
|
||||
},
|
||||
},
|
||||
)
|
||||
const { mutate: mutateAddToYearGroup } = useMutation(
|
||||
'addLeaderToGroup',
|
||||
(payload: { id: any; year_group_id: number; limit_group: number }) =>
|
||||
addLeaderToGroup(payload.id, payload.year_group_id, {
|
||||
limit_group: payload.limit_group,
|
||||
}),
|
||||
)
|
||||
|
||||
const onSubmit = (data: Leader) => {
|
||||
mutateCreateLeader(data)
|
||||
@ -83,7 +101,7 @@ const AddLeader = () => {
|
||||
<InputError>Email jest wymagany</InputError>
|
||||
)}
|
||||
</div>
|
||||
{/* <div className="form-control">
|
||||
<div className="form-control">
|
||||
<label className="label" htmlFor="limit_group">
|
||||
Limit grup
|
||||
</label>
|
||||
@ -99,7 +117,7 @@ const AddLeader = () => {
|
||||
{errors.limit_group?.type === 'pattern' && (
|
||||
<InputError>Limit grup musi być liczbą dodatnią</InputError>
|
||||
)}
|
||||
</div> */}
|
||||
</div>
|
||||
<button className="btn btn-success mt-4">Dodaj opiekuna</button>
|
||||
</form>
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user