2023-05-31 10:50:30 +00:00
|
|
|
import {create} from "zustand";
|
|
|
|
import {persist} from "zustand/middleware";
|
2023-10-23 15:33:56 +00:00
|
|
|
import { removeQuestionsByQuizId } from "./questions";
|
2023-05-14 11:00:37 +00:00
|
|
|
|
|
|
|
interface QuizStore {
|
2023-05-31 10:50:30 +00:00
|
|
|
listQuizes: { [key: number]: Quizes };
|
2023-05-26 18:27:33 +00:00
|
|
|
updateQuizesList: (id: number, values: unknown) => void;
|
2023-05-31 10:50:30 +00:00
|
|
|
removeQuiz: (id: number) => void;
|
2023-05-26 18:27:33 +00:00
|
|
|
createBlank: () => void;
|
2023-05-14 11:00:37 +00:00
|
|
|
}
|
|
|
|
|
2023-08-08 11:01:37 +00:00
|
|
|
export interface Quizes {
|
2023-05-14 11:00:37 +00:00
|
|
|
id: number,
|
|
|
|
qid: string,
|
|
|
|
deleted: boolean,
|
|
|
|
archived: boolean,
|
|
|
|
fingerprinting: boolean,
|
|
|
|
repeatable: boolean,
|
|
|
|
note_prevented: boolean,
|
|
|
|
mail_notifications: boolean,
|
2023-05-14 14:25:07 +00:00
|
|
|
unique_answers: boolean,
|
2023-05-14 11:00:37 +00:00
|
|
|
name: string,
|
|
|
|
description: string,
|
|
|
|
status: string,
|
|
|
|
limit: number,
|
|
|
|
due_to: number,
|
|
|
|
time_of_passing: number,
|
|
|
|
pausable: boolean,
|
|
|
|
version: number,
|
|
|
|
version_comment: string,
|
|
|
|
created_at: string,
|
|
|
|
updated_at: string,
|
|
|
|
question_cnt: number,
|
|
|
|
passed_count: number,
|
|
|
|
average_time: number,
|
|
|
|
super: true,
|
2023-05-31 10:50:30 +00:00
|
|
|
group_id: number,
|
2023-06-07 14:20:45 +00:00
|
|
|
step: number,
|
|
|
|
startpage: string,
|
2023-10-05 10:12:56 +00:00
|
|
|
createResult: boolean,
|
2023-06-17 22:26:12 +00:00
|
|
|
config: {
|
2023-06-13 21:59:16 +00:00
|
|
|
type: string,
|
|
|
|
logo: string,
|
2023-07-12 20:10:43 +00:00
|
|
|
noStartPage: boolean,
|
2023-06-13 21:59:16 +00:00
|
|
|
startpage: {
|
|
|
|
description: string,
|
|
|
|
button: string,
|
|
|
|
position: string,
|
|
|
|
background: {
|
|
|
|
type: string,
|
|
|
|
desktop: string,
|
|
|
|
mobile: string,
|
|
|
|
video: string,
|
|
|
|
cycle: boolean
|
|
|
|
},
|
|
|
|
},
|
|
|
|
info: {
|
|
|
|
phonenumber: string,
|
|
|
|
clickable: boolean,
|
|
|
|
orgname: string,
|
|
|
|
site: string,
|
|
|
|
law?: string
|
|
|
|
},
|
|
|
|
meta: string,
|
|
|
|
}
|
2023-05-14 11:00:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-20 17:22:13 +00:00
|
|
|
/** @deprecated */
|
2023-05-14 11:00:37 +00:00
|
|
|
export const quizStore = create<QuizStore>()(
|
|
|
|
persist(
|
|
|
|
(set, get) => ({
|
2023-05-31 10:50:30 +00:00
|
|
|
listQuizes: {
|
|
|
|
},
|
2023-05-26 18:27:33 +00:00
|
|
|
updateQuizesList: (id: number, values: any) => {
|
2023-05-14 14:25:07 +00:00
|
|
|
const state = get()["listQuizes"] || {};
|
2023-05-26 18:27:33 +00:00
|
|
|
state[id] = {
|
|
|
|
...state[id],
|
|
|
|
...values
|
2023-05-14 14:25:07 +00:00
|
|
|
};
|
2023-05-31 10:50:30 +00:00
|
|
|
set({listQuizes: state});
|
2023-05-14 14:25:07 +00:00
|
|
|
},
|
|
|
|
removeQuiz: (id) => {
|
|
|
|
const state = get()["listQuizes"] || {};
|
|
|
|
|
|
|
|
const newState = Object.entries(state).reduce<any>((accumulator, [key, value], index, array) => {
|
|
|
|
if (key !== id.toString()) {
|
|
|
|
accumulator[key] = value;
|
|
|
|
}
|
|
|
|
return accumulator;
|
|
|
|
}, {});
|
2023-05-31 10:50:30 +00:00
|
|
|
set({listQuizes: newState});
|
2023-10-23 15:33:56 +00:00
|
|
|
|
|
|
|
removeQuestionsByQuizId(id);
|
2023-05-26 18:27:33 +00:00
|
|
|
},
|
|
|
|
createBlank: () => {
|
|
|
|
const id = getRandom(1000000, 10000000)
|
|
|
|
const newListQuizes = get()["listQuizes"] || {};
|
|
|
|
newListQuizes[id] = {
|
2023-05-31 10:50:30 +00:00
|
|
|
"id": id,
|
|
|
|
"qid": "",
|
|
|
|
"deleted": false,
|
|
|
|
"archived": true,
|
|
|
|
"fingerprinting": true,
|
|
|
|
"repeatable": true,
|
|
|
|
"note_prevented": true,
|
|
|
|
"mail_notifications": true,
|
|
|
|
"unique_answers": true,
|
|
|
|
"name": "",
|
|
|
|
"description": "",
|
|
|
|
"status": "",
|
|
|
|
"limit": 0,
|
|
|
|
"due_to": 0,
|
|
|
|
"time_of_passing": 0,
|
|
|
|
"pausable": true,
|
|
|
|
"version": 0,
|
|
|
|
"version_comment": "",
|
|
|
|
"created_at": "",
|
|
|
|
"updated_at": "",
|
|
|
|
"question_cnt": 0,
|
|
|
|
"passed_count": 0,
|
|
|
|
"average_time": 0,
|
|
|
|
"super": true,
|
|
|
|
"group_id": 0,
|
2023-06-07 14:20:45 +00:00
|
|
|
"step": 1,
|
|
|
|
"startpage": "",
|
2023-10-05 10:12:56 +00:00
|
|
|
"createResult": false,
|
2023-06-17 22:26:12 +00:00
|
|
|
"config": {
|
2023-07-12 20:10:43 +00:00
|
|
|
"noStartPage": false,
|
2023-06-07 14:20:45 +00:00
|
|
|
"type": "", // quiz или form
|
|
|
|
"logo": "hub.pena.digital/img/logo",
|
|
|
|
"startpage": {
|
2023-06-17 22:26:12 +00:00
|
|
|
"description": "",// приветственный текст опроса
|
2023-10-17 10:53:19 +00:00
|
|
|
"button": "", // текст на кнопке начала опроса
|
2023-06-07 14:20:45 +00:00
|
|
|
"position": "ltr", // ltr или rtl. отображение элементов поверх фона
|
|
|
|
"background": {
|
|
|
|
"type": "image", //image или video
|
2023-11-01 13:31:15 +00:00
|
|
|
"desktop": "",
|
|
|
|
"mobile": "",
|
|
|
|
"video":"",
|
2023-06-07 14:20:45 +00:00
|
|
|
"cycle": true //зацикливать видео или нет
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"info": {
|
2023-10-17 10:53:19 +00:00
|
|
|
"phonenumber": "",
|
2023-06-07 14:20:45 +00:00
|
|
|
"clickable": true,
|
2023-10-17 10:53:19 +00:00
|
|
|
"orgname": "",
|
|
|
|
"site": "",
|
|
|
|
"law": ""
|
2023-06-07 14:20:45 +00:00
|
|
|
},
|
|
|
|
"meta": "что-то"
|
|
|
|
}
|
2023-05-26 18:27:33 +00:00
|
|
|
};
|
2023-05-31 10:50:30 +00:00
|
|
|
set({listQuizes: newListQuizes});
|
2023-05-26 18:27:33 +00:00
|
|
|
return id;
|
|
|
|
},
|
2023-05-14 11:00:37 +00:00
|
|
|
}),
|
|
|
|
{
|
|
|
|
name: "quizes",
|
|
|
|
}
|
|
|
|
)
|
2023-05-20 20:36:33 +00:00
|
|
|
);
|
|
|
|
|
2023-05-31 10:50:30 +00:00
|
|
|
function getRandom(min: number, max: number) {
|
2023-05-26 18:27:33 +00:00
|
|
|
min = Math.ceil(min);
|
|
|
|
max = Math.floor(max);
|
|
|
|
return Math.floor(Math.random() * (max - min)) + min;
|
2023-10-23 15:33:56 +00:00
|
|
|
}
|