Mik
August 5, 2021, 9:55am
1
Hi everyone.
I am developing a plugin that acts as a Dashboard Item.
The plugin is built in React. I have a cookie need and I decided to use the library:
Unfortunately, after saving the cookie, the value (undefined) could not be read. Locally - when I test the content (from another iframe server) it works fine. I tried to set the cookie domain parameter to the JIRA Cloud server domain but it didn’t work.
Perhaps it was wise to use AP.cookie
https://developer.atlassian.com/cloud/jira/platform/jsapi/cookie/
but unfortunately AP.cookie.read uses callback (instead of promise) - which is problematic in my case.
Could someone advise something on this?
Regards
Mik
Hi @Mik ,
Are you able to wrap AP.cookie.read
as follows:
readCookie = (name) => {
return new Promise((resolve, reject) => {
AP.cookie.read(name, (value) => {
resolve(value);
});
});
}
Regards,
Dugald
3 Likes
Mik
August 5, 2021, 10:41am
3
Hi @dmorrow Thank you - I will try use it
Regards
Mik
1 Like
Mik
August 5, 2021, 12:16pm
5
Hi @dmorrow
My functions looks like this:
export const saveCookie = (name: string, value: string, daysUntilExpiry: number) => {
if (!daysUntilExpiry) daysUntilExpiry = 365;
AP.cookie.save(name, value, daysUntilExpiry);
}
export const readCookieAsPromise = (name: string) => {
return new Promise((resolve, reject) => {
AP.cookie.read(name, (value: string) => {
resolve(value);
reject(value);
});
});
}
but If I’m trying
useEffect(() => {
saveCookie('TestCookieAsPromise', 'MikTesting4', 1)
let promisedCookieValue = readCookieAsPromise('CookieAsPromiseVALUE')
Promise.all([promisedCookieValue]).then((values) => {
console.log(values);
});
},
Plugin will not start.
Strange…
Regards
Mik
Mik
August 5, 2021, 1:31pm
6
Hi again @dmorrow
Please ignore last message. It was another reason.
I can confirm that your function working fine!
Thank you for help.
Best regards
Mik
1 Like
Thanks for the confirmation.
1 Like