Current Path : /home/ncdcgo/admin.ncdc.go.ug/static/js/ |
Current File : /home/ncdcgo/admin.ncdc.go.ug/static/js/13.38aff9c4.chunk.js.map |
{"version":3,"sources":["features/faqs/api/getFaq.js","features/faqs/api/updateFaq.js","features/faqs/components/UpdateFaq.jsx","features/faqs/routes/Faq.jsx","features/faqs/api/createFaq.js","features/faqs/components/CreateFaq.jsx","features/faqs/api/getFaqs.js","features/faqs/api/deleteFaq.js","features/faqs/components/DeleteFaq.jsx","features/faqs/components/FaqsList.jsx","features/faqs/routes/Faqs.jsx","features/faqs/routes/index.jsx"],"names":["useFaq","faqId","config","useQuery","queryKey","queryFn","axios","get","getFaq","updateFaq","data","patch","propTypes","PropTypes","shape","question","string","isRequired","answer","category","schema","z","min","UpdateFaq","faqQuery","updateFaqMutation","addNotification","useNotificationStore","useMutation","onMutate","updatingFaq","a","queryClient","cancelQueries","previousFaq","getQueryData","setQueryData","id","onError","_","__","context","onSuccess","refetchQueries","type","title","mutationFn","useUpdateFaq","categoriesQuery","label","value","allowedRoles","ROLES","ADMIN","Form","sie","isDone","isSuccess","triggerButton","startIcon","className","size","submitButton","form","isLoading","onSubmit","values","mutateAsync","options","defaultValues","register","formState","watch","setValue","error","errors","registration","editorContent","map","Faq","useParams","Head","button","createFaq","post","CreateFaq","createFaqMutation","newJob","previousFaqs","invalidateQueries","useCreateFaq","getFaqs","deleteFaq","delete","DeleteFaq","deleteFaqMutation","deletedFaq","filter","faq","useDeleteFaq","icon","body","variant","confirmButton","onClick","postId","FaqsList","faqsQuery","useFaqs","columns","field","Cell","_id","entry","to","Faqs","FaqsRoutes","path","element"],"mappings":"gOAOaA,EAAS,SAAC,GAAuB,IAArBC,EAAoB,EAApBA,MAAOC,EAAa,EAAbA,OAC9B,OAAOC,YAAS,2BACXD,GADU,IAEbE,SAAU,CAAC,MAAOH,GAClBI,QAAS,kBARS,SAAC,GAAe,IAAbJ,EAAY,EAAZA,MACvB,OAAOK,IAAMC,IAAN,gBAAmBN,IAOT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cAAC,IAAD,CAAUJ,GAAG","file":"static/js/13.38aff9c4.chunk.js","sourcesContent":["import { axios } from '@/lib/axios';\nimport { useQuery } from 'react-query';\n\nexport const getFaq = ({ faqId }) => {\n return axios.get(`/faqs/${faqId}`);\n};\n\nexport const useFaq = ({ faqId, config }) => {\n return useQuery({\n ...config,\n queryKey: ['faq', faqId],\n queryFn: () => getFaq({ faqId }),\n });\n};\n","import { axios } from '@/lib/axios';\nimport { queryClient } from '@/lib/react-query';\nimport { useNotificationStore } from '@/stores/notifications';\nimport PropTypes from 'prop-types';\nimport { useMutation } from 'react-query';\n\nexport const updateFaq = ({ data, faqId }) => {\n return axios.patch(`/faqs/${faqId}`, data);\n};\n\nupdateFaq.propTypes = {\n data: PropTypes.shape({\n question: PropTypes.string.isRequired,\n answer: PropTypes.string.isRequired,\n category: PropTypes.string.isRequired,\n }).isRequired,\n faqId: PropTypes.string.isRequired,\n};\n\nexport const useUpdateFaq = ({ config } = {}) => {\n const { addNotification } = useNotificationStore();\n\n return useMutation({\n onMutate: async (updatingFaq) => {\n await queryClient.cancelQueries(['faq', updatingFaq?.faqId]);\n\n const previousFaq = queryClient.getQueryData[('faq', updatingFaq?.faqId)];\n\n queryClient.setQueryData(['faq', updatingFaq?.faqId], {\n ...previousFaq,\n ...updatingFaq.data,\n id: updatingFaq.faqId,\n });\n\n return { previousFaq };\n },\n onError: (_, __, context) => {\n if (context?.previousFaq) {\n queryClient.setQueryData(['faq', context.previousFaq.id], context.previousFaq);\n }\n },\n onSuccess: (data) => {\n queryClient.refetchQueries(['faq', data.id]);\n addNotification({\n type: 'success',\n title: 'Faq Updated',\n });\n },\n ...config,\n mutationFn: updateFaq,\n });\n};\n","import { Button } from '@/components/Elements';\nimport { Form, FormDrawer, InputField, SelectField, TextAreaField } from '@/components/Form';\nimport { Authorization, ROLES } from '@/lib/authorization';\nimport { PencilIcon } from '@heroicons/react/solid';\nimport PropTypes from 'prop-types';\nimport * as z from 'zod';\n\nimport { useFaq } from '../api/getFaq';\nimport { useUpdateFaq } from '../api/updateFaq';\n\nconst schema = z.object({\n question: z.string().min(1, 'Required'),\n answer: z.string().min(1, 'Required'),\n category: z.string().min(1, 'Required'),\n});\n\nexport const UpdateFaq = ({ faqId }) => {\n const faqQuery = useFaq({ faqId });\n const updateFaqMutation = useUpdateFaq();\n\n const categoriesQuery = [\n { label: 'Secondary Education', value: 'Secondary Education' },\n { label: 'Primary Education', value: 'Primary Education' },\n { label: 'ECCE', value: 'ECCE' },\n { label: 'BTVET', value: 'BTVET' },\n ];\n\n return (\n <Authorization allowedRoles={[ROLES.ADMIN]}>\n <FormDrawer\n sie=\"sm\"\n isDone={updateFaqMutation.isSuccess}\n triggerButton={\n <Button startIcon={<PencilIcon className=\"h-4 w-4\" />} size=\"sm\">\n Update Job\n </Button>\n }\n title=\"Update Faq\"\n submitButton={\n <Button form=\"update-job\" type=\"submit\" size=\"sm\" isLoading={updateFaqMutation.isLoading}>\n Submit\n </Button>\n }\n >\n <Form\n id=\"update-job\"\n onSubmit={async (values) => {\n await updateFaqMutation.mutateAsync({ data: values, faqId });\n }}\n options={{\n defaultValues: {\n question: faqQuery.data?.question,\n answer: faqQuery.data?.answer,\n category: faqQuery.data?.category,\n },\n }}\n schema={schema}\n >\n {({ register, formState, watch, setValue }) => (\n <>\n <InputField\n label=\"Question\"\n error={formState.errors['question']}\n registration={register('question')}\n />\n <TextAreaField\n label=\"Answer\"\n error={formState.errors['answer']}\n editorContent={watch('answer')}\n setValue={setValue}\n value=\"answer\"\n />\n <SelectField\n label=\"Category\"\n error={formState.errors['category']}\n registration={register('category')}\n options={categoriesQuery?.map((category) => ({\n label: category.label,\n value: category.value,\n }))}\n />\n </>\n )}\n </Form>\n </FormDrawer>\n </Authorization>\n );\n};\n\nUpdateFaq.propTypes = {\n faqId: PropTypes.string.isRequired,\n};\n","import { Spinner, MDPreview } from '@/components/Elements';\nimport { Head } from '@/components/Head';\nimport { ContentLayout } from '@/components/Layout';\nimport { useParams } from 'react-router-dom';\n\nimport { useFaq } from '../api/getFaq';\nimport { UpdateFaq } from '../components/UpdateFaq';\n\nexport const Faq = () => {\n const { faqId } = useParams();\n const faqQuery = useFaq({ faqId });\n\n if (faqQuery.isLoading) {\n return (\n <div className=\"w-full h-48 flex justify-center items-center\">\n <Spinner size=\"lg\" />\n </div>\n );\n }\n\n if (!faqQuery.data) return null;\n\n return (\n <>\n <Head title={faqQuery.data.question} />\n <ContentLayout title={faqQuery.data.question} button={<UpdateFaq faqId={faqId} />}>\n <span className=\"text-xs font-bold bg-green-400 p-1 rounded text-white\">\n {faqQuery.data.category}\n </span>\n <div className=\"mt-6 flex flex-col space-y-16\">\n <div>\n <div className=\"bg-white shadow overflow-hidden sm:rounded-lg\">\n <div className=\"px-4 py-5 sm:px-6\">\n <div className=\"mt-1 max-w-2xl text-sm text-gray-500\">\n <MDPreview value={faqQuery.data.answer} />\n </div>\n </div>\n </div>\n </div>\n </div>\n </ContentLayout>\n </>\n );\n};\n","import { axios } from '@/lib/axios';\nimport { queryClient } from '@/lib/react-query';\nimport { useNotificationStore } from '@/stores/notifications';\nimport PropTypes from 'prop-types';\nimport { useMutation } from 'react-query';\n\nexport const createFaq = ({ data }) => {\n return axios.post(`/faqs`, data);\n};\n\ncreateFaq.propTypes = {\n data: PropTypes.shape({\n question: PropTypes.string.isRequired,\n answer: PropTypes.string.isRequired,\n category: PropTypes.string.isRequired,\n }).isRequired,\n};\n\nexport const useCreateFaq = ({ config } = {}) => {\n const { addNotification } = useNotificationStore();\n return useMutation({\n onMutate: async (newJob) => {\n await queryClient.cancelQueries('faqs');\n\n const previousFaqs = queryClient.getQueryData('faqs');\n\n queryClient.setQueryData('faqs', [...(previousFaqs || []), newJob.data]);\n\n return { previousFaqs };\n },\n onError: (_, __, context) => {\n if (context?.previousFaqs) {\n queryClient.setQueryData('faqs', context.previousFaqs);\n }\n },\n onSuccess: () => {\n queryClient.invalidateQueries('faqs');\n addNotification({\n type: 'success',\n title: 'Faq has been added',\n });\n },\n ...config,\n mutationFn: createFaq,\n });\n};\n","import { Button } from '@/components/Elements';\nimport { Form, FormDrawer, InputField, SelectField, TextAreaField } from '@/components/Form';\nimport { Authorization, ROLES } from '@/lib/authorization';\nimport { PlusIcon } from '@heroicons/react/outline';\nimport * as z from 'zod';\n\nimport { useCreateFaq } from '../api/createFaq';\n\nconst schema = z.object({\n question: z.string().min(1, 'Required'),\n answer: z.string().min(1, 'Required'),\n category: z.string().min(1, 'Required'),\n});\n\nexport const CreateFaq = () => {\n const createFaqMutation = useCreateFaq();\n\n const categoriesQuery = [\n { label: 'Secondary Education', value: 'Secondary Education' },\n { label: 'Primary Education', value: 'Primary Education' },\n { label: 'ECCE', value: 'ECCE' },\n { label: 'BTVET', value: 'BTVET' },\n ];\n\n return (\n <Authorization allowedRoles={[ROLES.ADMIN]}>\n <FormDrawer\n size=\"sm\"\n isDone={createFaqMutation.isSuccess}\n triggerButton={\n <Button size=\"sm\" startIcon={<PlusIcon className=\"h-4 w-4\" />}>\n Create Faq\n </Button>\n }\n title=\"Create Faq\"\n submitButton={\n <Button form=\"create-faq\" type=\"submit\" size=\"sm\" isLoading={createFaqMutation.isLoading}>\n Submit\n </Button>\n }\n >\n <Form\n id=\"create-faq\"\n onSubmit={async (values) => {\n await createFaqMutation.mutateAsync({ data: values });\n }}\n schema={schema}\n >\n {({ register, formState, watch, setValue }) => (\n <>\n <InputField\n label=\"Question\"\n error={formState.errors['question']}\n registration={register('question')}\n />\n <TextAreaField\n label=\"Answer\"\n error={formState.errors['answer']}\n editorContent={watch('answer')}\n setValue={setValue}\n value=\"answer\"\n />\n <SelectField\n label=\"Category\"\n error={formState.errors['category']}\n registration={register('category')}\n options={categoriesQuery?.map((category) => ({\n label: category.label,\n value: category.value,\n }))}\n />\n </>\n )}\n </Form>\n </FormDrawer>\n </Authorization>\n );\n};\n","import { axios } from '@/lib/axios';\nimport { useQuery } from 'react-query';\n\nexport const getFaqs = () => {\n return axios.get('/faqs');\n};\n\nexport const useFaqs = ({ config } = {}) => {\n return useQuery({\n ...config,\n queryKey: ['faqs'],\n queryFn: () => getFaqs(),\n });\n};\n","import { axios } from '@/lib/axios';\nimport { queryClient } from '@/lib/react-query';\nimport { useNotificationStore } from '@/stores/notifications';\nimport PropTypes from 'prop-types';\nimport { useMutation } from 'react-query';\n\nexport const deleteFaq = ({ faqId }) => {\n return axios.delete(`/faqs/${faqId}`);\n};\n\ndeleteFaq.propTypes = {\n faqId: PropTypes.string.isRequired,\n};\n\nexport const useDeleteFaq = ({ config } = {}) => {\n const { addNotification } = useNotificationStore();\n\n return useMutation({\n onMutate: async (deletedFaq) => {\n await queryClient.cancelQueries('jobs');\n\n const previousFaqs = queryClient.getQueryData('jobs');\n\n queryClient.setQueryData(\n 'jobs',\n previousFaqs?.filter((faq) => faq.id !== deletedFaq.faqId)\n );\n\n return { previousFaqs };\n },\n onError: (_, __, context) => {\n if (context?.previousFaqs) {\n queryClient.setQueryData('jobs', context.previousFaqs);\n }\n },\n onSuccess: () => {\n queryClient.invalidateQueries('faqs');\n addNotification({\n type: 'success',\n title: 'Faq Deleted',\n });\n },\n ...config,\n mutationFn: deleteFaq,\n });\n};\n","import { Button, ConfirmationDialog } from '@/components/Elements';\nimport { Authorization, ROLES } from '@/lib/authorization';\nimport { TrashIcon } from '@heroicons/react/outline';\nimport PropTypes from 'prop-types';\n\nimport { useDeleteFaq } from '../api/deleteFaq';\n\nexport const DeleteFaq = ({ id }) => {\n const deleteFaqMutation = useDeleteFaq();\n\n return (\n <Authorization allowedRoles={[ROLES.ADMIN]}>\n <ConfirmationDialog\n icon=\"danger\"\n title=\"Delete Faq\"\n body=\"Are you sure you want to delete this Faq?\"\n triggerButton={\n <Button variant=\"danger\">\n <TrashIcon className=\"h-4 w-4\" />\n </Button>\n }\n confirmButton={\n <Button\n isLoading={deleteFaqMutation.isLoading}\n type=\"button\"\n className=\"bg-red-600\"\n onClick={async () => await deleteFaqMutation.mutateAsync({ postId: id })}\n >\n Delete Faq\n </Button>\n }\n />\n </Authorization>\n );\n};\n\nDeleteFaq.propTypes = {\n id: PropTypes.string.isRequired,\n};\n","import { Table, Spinner, Link } from '@/components/Elements';\n\nimport { useFaqs } from '../api/getFaqs';\n\nimport { DeleteFaq } from './DeleteFaq.jsx';\n\nexport const FaqsList = () => {\n const faqsQuery = useFaqs();\n\n if (faqsQuery.isLoading) {\n return (\n <div className=\"w-full h-48 flex justify-center items-center\">\n <Spinner size=\"lg\" />\n </div>\n );\n }\n\n if (!faqsQuery.data) return null;\n\n return (\n <Table\n data={faqsQuery.data}\n columns={[\n {\n title: 'Question',\n field: 'question',\n },\n {\n title: '',\n field: 'id',\n Cell({ entry: { _id } }) {\n return <Link to={`./${_id}`}>View</Link>;\n },\n },\n {\n title: '',\n field: 'id',\n Cell({ entry: { _id } }) {\n return <DeleteFaq id={_id} />;\n },\n },\n ]}\n />\n );\n};\n","import { ContentLayout } from '@/components/Layout';\n\nimport { CreateFaq } from '../components/CreateFaq';\nimport { FaqsList } from '../components/FaqsList';\n\nexport const Faqs = () => {\n return (\n <ContentLayout title=\"Faqs\" button={<CreateFaq />}>\n <div className=\"mt-4\">\n <FaqsList />\n </div>\n </ContentLayout>\n );\n};\n","import { Navigate, Route, Routes } from 'react-router-dom';\n\nimport { Faq } from './Faq';\nimport { Faqs } from './Faqs';\n\nexport const FaqsRoutes = () => {\n return (\n <Routes>\n <Route path=\"\" element={<Faqs />} />\n <Route path=\":faqId\" element={<Faq />} />\n <Route path=\"*\" element={<Navigate to=\".\" />} />\n </Routes>\n );\n};\n"],"sourceRoot":""}