Skip to content

Commit

Permalink
Merge pull request #199 from LL08-MathematicalModelling-dowell/fronte…
Browse files Browse the repository at this point in the history
…nd-Norah

Nps scale and nps scale fixes
  • Loading branch information
norahwinda authored Feb 2, 2024
2 parents 1f9c846 + 4e704c1 commit c2412b3
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 31 deletions.
17 changes: 11 additions & 6 deletions src/pages/scales/nps-lite-scale/CreateNpsLiteScale.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const CreateNpsLiteScale = () => {
const handleChange = (e)=>{
const { name, value } = e.target;
setFormData({ ...formData, [name]:value });
if (name === 'fomat' && value === 'Emojis') {
if (name === 'fomat' && value === 'emoji') {
console.log('fomat selected:', value)
handleToggleEmojiPellete();
} else {
Expand Down Expand Up @@ -94,7 +94,7 @@ const CreateNpsLiteScale = () => {
}

const orientation = ['Vertical', 'Horizontal']
const format = ['Numbers', 'Emojis']
const format = ['Numbers', 'emoji']

const handleSubmitNPSScale = async()=>{

Expand Down Expand Up @@ -126,8 +126,13 @@ const CreateNpsLiteScale = () => {

for(const field of requiredFields){
if(!formData[field]){
if(formData.format === "emoji" && field === 'left','center', 'right') {

}else {
toast.error(`Please complete the "${field}" field.`);
return;
}

}
}
try {
Expand Down Expand Up @@ -252,7 +257,7 @@ const CreateNpsLiteScale = () => {
<CustomTextInput
label='left'
name='left'
value={formData.fomat === 'Emojis' ? selectedEmojis[0] :formData.left}
value={formData.fomat === 'emoji' ? selectedEmojis[0] :formData.left}
type='text'
handleChange={handleChange}
placeholder='enter scale left'
Expand All @@ -262,7 +267,7 @@ const CreateNpsLiteScale = () => {
<CustomTextInput
label='center'
name='center'
value={ formData.fomat === 'Emojis' ? selectedEmojis[1] : formData.center}
value={ formData.fomat === 'emoji' ? selectedEmojis[1] : formData.center}
type='text'
handleChange={handleChange}
placeholder='enter scale center'
Expand All @@ -272,7 +277,7 @@ const CreateNpsLiteScale = () => {
<CustomTextInput
label='right'
name='right'
value={formData.fomat === 'Emojis' ? selectedEmojis[2] : formData.right}
value={formData.fomat === 'emoji' ? selectedEmojis[2] : formData.right}
type='text'
handleChange={handleChange}
placeholder='enter scale right'
Expand Down Expand Up @@ -317,7 +322,7 @@ const CreateNpsLiteScale = () => {
)}
</div>
<div className='flex justify-end gap-3'>
{isLoading ? <Fallback/> : <button onClick={handleSubmitNPSScale} className='py-2 px-3 bg-primary text-white min-w-[10rem] hover:bg-gray-600 hover:text-white font-medium'>Save</button>}
{isLoading ? <Fallback/> : <button onClick={handleSubmitNPSScale} className='w-full py-2 px-3 bg-primary text-white min-w-[10rem] hover:bg-gray-600 hover:text-white font-medium'>Save</button>}
{/* <button className='py-2 px-3 bg-primary text-white min-w-[10rem] hover:bg-gray-600 hover:text-white font-medium'>Preview</button> */}
</div>
</div>
Expand Down
63 changes: 46 additions & 17 deletions src/pages/scales/nps-lite-scale/NpsLiteSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ const NpsLiteSettings = () => {
const qrcode_id = queryParams.get('qrcode_id');
const [isButtonHidden, setIsButtonHidden] = useState(false);
const [scaleArr, setScaleArr] = useState([])
const [instance, setInstance] = useState(false)

let scores = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let currentUserInstance = new URLSearchParams(window.location.search).get(
'instance_id'
)

const handleButtonHideClick = () => {
// Perform the click action
Expand Down Expand Up @@ -67,14 +71,15 @@ const NpsLiteSettings = () => {
// await fetchSingleScaleData(scaleId);
// };

const submitResponse = async () => {
const info = await axios.post(
'https://100093.pythonanywhere.com/api/userinfo/',
{
// session_id: "p1frwekqkwq05ia3fajjujwgvjjz1ovy",
session_id: sessionStorage.getItem('session_id'),
}
);
const submitResponse = async (e) => {
e.preventDefault()
// const info = await axios.post(
// 'https://100093.pythonanywhere.com/api/userinfo/',
// {
// // session_id: "p1frwekqkwq05ia3fajjujwgvjjz1ovy",
// session_id: sessionStorage.getItem('session_id'),
// }
// );

// const result = info.data;
// console.log(result.userinfo);
Expand All @@ -101,6 +106,7 @@ const NpsLiteSettings = () => {
payload
);
const result = response.data;

console.log(result.success);
if (result.error) {
setIsLoading(false);
Expand All @@ -116,6 +122,8 @@ const NpsLiteSettings = () => {
setIsLoading(false);
}
};

console.log("HHHHHHHHHHHHHHHHHHHHHHHHTTTTTTTTT", instance)

const finalizeMasterlink = async () => {
setIsLoading(true);
Expand Down Expand Up @@ -187,9 +195,19 @@ const NpsLiteSettings = () => {
const response = await axios.get(
`https://100035.pythonanywhere.com/nps-lite/api/nps-lite-response?id=${slug}`
);
setScaleResponse((response.data.data.data[0]).score);

(response.data.data.data).map((value) =>{
if((value.process_id) === link_id) {
setScaleResponse((value.score));
if((value.score.instance_id).charAt(0) === currentUserInstance) {
setInstance(true)
}else {
setInstance(false)
}
}
})

setResponse(response.data)
console.log("hhhhhhhhhhhhhhhhhbbbbbbb", response.data)
} catch (error) {
console.error(error);
} finally {
Expand Down Expand Up @@ -366,7 +384,7 @@ const NpsLiteSettings = () => {
</h3>}
<div
className={`grid md:gap-3 md:px-2 py-6 grid-cols-11 md:px-1 items-center justify-center place-items-center`}
style={{display:'flex', flexDirection: scale?.orientation === "Vertical" ? "column" : "",alignItems:'center', justifyContent: 'center', fontSize: 'small', overflow: 'auto', width:scale?.orientation === "Vertical" ? "7rem" : "", borderRadius:"8px" }}
style={{display:'flex', flexDirection: scale?.orientation === "Vertical" ? "column" : "", alignItems:'center', justifyContent: 'center', fontSize: 'small', overflow: 'auto', width:scale?.orientation === "Vertical" ? "7rem" : "", borderRadius:"8px" }}
>
{scale &&
scale?.label_selection ?
Expand All @@ -376,19 +394,30 @@ const NpsLiteSettings = () => {
key={index}
id = {index}
onClick={() => handleSelectScore(score, index)}
disabled = {scaleResponse.length === 0 ? false : true}
disabled = {scaleResponse.length === 0 ? false : (instance ? true : false)}
className={`rounded-lg ${index === selectedScore
? 'bg-white' : 'bg-primary text-white'} text-primary h-[3.8rem] w-[3.8rem]`}

// style={
// index == selectedScore || (scaleResponse.score === index && instance)
// ? {
// backgroundColor: 'green',
// color: 'white',
// }
// : { backgroundColor: scale?.roundcolor,color: scale?.fontcolor }
// }

style={
index == selectedIndex || scaleResponse.score === index
index == selectedIndex || (scaleResponse.score -1) === index && instance
? {
backgroundColor: 'green',
color: 'white',
color: 'white', width: '30%'
}
: { backgroundColor: scale?.scalecolor, color: scale?.fontcolor }
: { backgroundColor: scale?.scalecolor, color: scale?.fontcolor, width: '30%' }

}
>
{score}
{(scale?.custom_emoji_format).length !== 0 ? (scale?.custom_emoji_format)[index] : score}
</button>
)
) : scaleArr.map((score, index) =>(
Expand Down Expand Up @@ -436,7 +465,7 @@ const NpsLiteSettings = () => {
<>
{!isButtonHidden && (
<div className="flex items-center justify-center my-4">
{scaleResponse.length === 0 && <Button width={'3/12'} primary onClick={submitResponse}>
{!instance && <Button width={'3/12'} primary onClick={submitResponse}>
{isLoading ? 'Submitting' : 'Submit'}
</Button>
}
Expand Down
18 changes: 10 additions & 8 deletions src/pages/scales/nps-scale/NPSScaleSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ const NPSScaleSettings = () => {
// };

const submitResponse = async () => {
const info = await axios.post(
'https://100093.pythonanywhere.com/api/userinfo/',
{
// session_id: "p1frwekqkwq05ia3fajjujwgvjjz1ovy",
session_id: sessionStorage.getItem('session_id'),
}
);
// const info = await axios.post(
// 'https://100093.pythonanywhere.com/api/userinfo/',
// {
// // session_id: "p1frwekqkwq05ia3fajjujwgvjjz1ovy",
// session_id: sessionStorage.getItem('session_id'),
// }
// );

// const result = info.data;
// console.log(result.userinfo);
Expand Down Expand Up @@ -184,14 +184,16 @@ const NPSScaleSettings = () => {
const response = await axios.get(
`https://100035.pythonanywhere.com/api/nps_responses_create?scale_id=${slug}`
);
setScaleResponse((response.data.data.data[0]).score);

(response.data.data.data).map((value) =>{
if((value.process_id) === link_id) {
setScaleResponse((value.score));
if((value.score.instance_id).charAt(0) === currentUserInstance) {
setInstance(true)
}else {
setInstance(false)
}
}
})

setResponse((response.data.data.data))
Expand Down

0 comments on commit c2412b3

Please sign in to comment.